Copy-webpack-plugin: [Bug] Plugin patterns copy parents

Created on 15 Sep 2017  路  3Comments  路  Source: webpack-contrib/copy-webpack-plugin

{
  "to": "assets",
  "from": {
    "glob": "src/assets/**/*",
    "dot": true
  }
}

this ends up creating "dist/assets/src/assets" instead of copying all sub-dirs/files from src/assets into assets/

Why would I end up with assets/src/assets if the glob pattern is all subdirectories/files inside src/assets?

Thanks

Bug

Most helpful comment

@nickenchev : The following configuration seemed to resolve the issue for me. This may help in your case as well:
{ "context": './src/assets/', "from": '**/*', "to": './assets/' },

One caveat here is that my webpack config file is within a folder called 'webpack' and not at project root level, (the folder contains specific webpack files for different environments) so I have moved up a level in the hierarchy using the './' in the paths.

If your webpack config file is at the root level, you can simply use 'src/assets/' for the "context" parameter

All 3 comments

I have the same issue. Attaching my configuration below:
new CopyWebpackPlugin([{ "from": "src/assets/**/*.*", "to": "assets", "toType": "dir" }], { "ignore": [ ".gitkeep" ], "debug": "warning" })

@nickenchev : The following configuration seemed to resolve the issue for me. This may help in your case as well:
{ "context": './src/assets/', "from": '**/*', "to": './assets/' },

One caveat here is that my webpack config file is within a folder called 'webpack' and not at project root level, (the folder contains specific webpack files for different environments) so I have moved up a level in the hierarchy using the './' in the paths.

If your webpack config file is at the root level, you can simply use 'src/assets/' for the "context" parameter

@nickenchev @jcardoz plugin works as expected by default context (compiler.options.context - example /path/to/src), glob with default cwd options (compiler.options.context) return src/assets/file.txt.
Output directory /path/to/dist, to interpreted as /path/to/dist/assets/ + src/assets/file.txt. For resolve this issue see comment above. In short - use context option. Thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cletusw picture cletusw  路  5Comments

jbruni picture jbruni  路  3Comments

amgohan picture amgohan  路  5Comments

kimgysen picture kimgysen  路  3Comments

BoldBigflank picture BoldBigflank  路  6Comments