Copy-webpack-plugin: Windows regex not passing group data

Created on 4 Mar 2019  路  6Comments  路  Source: webpack-contrib/copy-webpack-plugin

  • Operating System: Windows
  • Node Version: v6.14.1
  • NPM Version: 5.8.0
  • webpack Version: 4.16.2
  • copy-webpack-plugin Version: 5.0.0

Expected Behavior

I expect my copy plugin will move json files to a different directory with a different name based on the name of the folder it came from. For example: app/js/games/aspen/json/test.json will move to /json/aspen-test.json

Actual Behavior

On Windows, this copies the literal '[1]-test.json' to the new directory, rather than the name of the first capturing group. This works properly in Linux.

Code

new CopyWebpackPlugin([
            {
                from: 'app/js/**/test.json',
                to: 'json/[1]-test.json',
                test:/app\/js\/(?:games|controllers)\/([^/]+)\/json\/test.json/
            }])

How Do We Reproduce?

I think using this plugin code in a small repository with a similar directory structure will show the proper result.

Has pull request 4 (important) Major 3 (broken) Bug

Most helpful comment

We remove the test option in favor transformPath, using the transformPath option allow to implement any logic, even async, no need write hard to read regexps

All 6 comments

Thanks for issue, i think problem related to loader-utils, i will see in near future

Just note: /app\/js\/(?:games|controllers)\/([^/]+)\/json\/test.json/ should be /app\/js\/(?:games|controllers)\/([^/]+)\/json\/test\.json/ (you forget \.). Investigate what is problem.

Problem not in copy-webpack-plugin. Problem in loader-utils as i written above (https://github.com/webpack/loader-utils/blob/master/lib/interpolateName.js#L110). resourcePath contains platform specific path separator, so you regexp doesn't work on windows, unfortunately we can't fix it on plugins side and we can't fix it without major release loader-utils. I created issue https://github.com/webpack/loader-utils/issues/143, we fix it for v2. As workaround you can use (/|\\) instead / in regexp. I closing issue in favor https://github.com/webpack/loader-utils/issues/143. Thanks!

Find problem https://github.com/webpack-contrib/copy-webpack-plugin/pull/353, with one side it is fix, with other it is breaking change, i am afraid release this as patch

Could you at least put a note in the readme about this until a fix is available?

We remove the test option in favor transformPath, using the transformPath option allow to implement any logic, even async, no need write hard to read regexps

Was this page helpful?
0 / 5 - 0 ratings

Related issues

amgohan picture amgohan  路  5Comments

stq picture stq  路  5Comments

Jocs picture Jocs  路  4Comments

jdeniau picture jdeniau  路  5Comments

kimgysen picture kimgysen  路  3Comments