Laravel-mix: A directory with subdirectories is flattened when copied

Created on 24 Jan 2017  路  3Comments  路  Source: JeffreyWay/laravel-mix

The flatten option was added to te copy command since this commit https://github.com/JeffreyWay/laravel-mix/pull/135/commits/4cee266181d5d8fc96d4ad6e19276e2b900b4d0b, now how to copy a directory without flattening it ?

Most helpful comment

I just a merged a PR that allows you to specify whether or not to flatten the output. Pass it as the third argument to mix.copy('from, 'to', false).

All 3 comments

i'm facing the same issue right now if i try to copy directory into new location all files within old directory got flatten in the new directory by default and there is no option to control it

/**
 * Copy one or more files to a new location.
 *
 * @param {string} from
 * @param {string} to
 */
module.exports.copy = (from, to) => {
    Mix.copy = (Mix.copy || []).concat({
        from,
        to: Mix.Paths.root(to),
        flatten: true
    });

    return this;
};

i changed it into

/**
 * Copy one or more files to a new location.
 *
 * @param {string} from
 * @param {string} to
 */
module.exports.copy = (from, to, flatten = true) => {
    Mix.copy = (Mix.copy || []).concat({
        from,
        to: Mix.Paths.root(to),
        flatten: flatten
    });

    return this;
};

to fix the issue for now

The flatten was added as a workaround for folder ambiguities when copying a tree with just src and dest args. #101

Instead I've used the 'context' copy-webpack-plugin option. Context allows you to specify the root that the copy is relative to - rather than implying it all from the 'from' arg (same as the cwd option to glob). Flatten shouldn't be necessary.

Something like:

mix.copy2 = function (from, to, root) {
    var options = {
        from: from,
        to: Mix.Paths.root(to)
    };
    if (root) {
        options.context = Mix.Paths.root(root);
    }
    Mix.copy = (Mix.copy || []).concat(options);
};

I just a merged a PR that allows you to specify whether or not to flatten the output. Pass it as the third argument to mix.copy('from, 'to', false).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tillkruss picture tillkruss  路  3Comments

mementoneli picture mementoneli  路  3Comments

Micaso picture Micaso  路  3Comments

amin101 picture amin101  路  3Comments

dtheb picture dtheb  路  3Comments