Copy-webpack-plugin: Conflict with clean-webpack-plugin?

Created on 19 May 2018  路  14Comments  路  Source: webpack-contrib/copy-webpack-plugin

When I use clean-webpack-plugin with copy-webpack-plugin, I got ERROR in [copy-webpack-plugin] unable to locate 'dist/manage.bundle.js' at '/Users/XXX/Workspace/project/dist/manage.bundle.js', but when I remove clean-webpack-plugin, it works fine, what the problem is?

    plugins: [
        new CleanWebpackPlugin(['dist']),
        new UglifyJSPlugin({
            sourceMap: true
        }),
        new CopyWebpackPlugin([
            {
                from: 'dist/manage.bundle.js',
                to: '../public/js/'
            }
        ], { debug: 'info' })
    ],
Major 3 (broken) Bug

Most helpful comment

update CleanWebpackPlugin options like:

new CleanWebpackPlugin({
    cleanStaleWebpackAssets: false, // resolve conflict with `CopyWebpackPlugin`
}),

All 14 comments

@kevinzheng because CleanWebpackPlugin remove dist/manage.bundle.js, it is expected

@evilebottnawi How can I do CopyWebpackPlugin at the end of the build?

@kevinzheng i don't understand your, you remove files and when want to copy this file?

@evilebottnawi , I want to clean-webpack-plugin before the compiling, and copy-webpack-plugin after the compiling, ehh... I want to clean the dist dir before building, and copy the building result to another dir.

@kevinzheng out of scope copy-webpack-plugin, use any copy package or system utils to move something after build process.

same here..

update CleanWebpackPlugin options like:

new CleanWebpackPlugin({
    cleanStaleWebpackAssets: false, // resolve conflict with `CopyWebpackPlugin`
}),

Somebody can create reproducible test repo?

The issue is copy-webpack-plugin does not persist the assets copied in webpack's current asset list. I attempted to resolve this issue in #360 but the PR looks to be stale. If a maintainer can provide some insight on how to move that PR forward I would be willing to make the necessary changes to solve this.

@chrisblossom this PR is breaking change, we will fix it in next release

cleanStaleWebpackAssets: false does not solve the problem for me.

I use CopyWebpackPlugin to copy static files into the bulid folder:

  plugins: [
    new CleanWebpackPlugin(),
    new MiniCssExtractPlugin({
      filename: '[name].[hash].css',
    }),
    new WebpackMd5Hash(),
    new CopyPlugin([
      { from: 'public', to: '.' }
    ]),
  ],

If I use webpack --watch, everything seems to work on the first build. But from the second bulid onward, the static assets are removed by CleanWebpackPlugin (which is correct, because they might have been modified) but they are not copied again by CopyWebpackPlugin.

Edit: I solved it by adding copyUnmodified: true as an option, but this should still be considered a conflict with CleanWebpackPlugin IMHO.

@evilebottnawi can you estimate when a release with a fix will be available?

same problem

Hope current month

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dmarcautan picture dmarcautan  路  5Comments

lewayjack picture lewayjack  路  5Comments

RPDeshaies picture RPDeshaies  路  5Comments

nickenchev picture nickenchev  路  3Comments

alex88 picture alex88  路  4Comments