webpackwebpack-4

CopyWebpackPlugin - ignore a folder


Using CopyWebpackPlugin, I am not able to ignore a specific folder or a specific file. It copies everything.

What I have done in the webpack.config.js:

    new CopyWebpackPlugin([
        {
            from: 'src/assets',
            to: 'assets',
            ignore: ['src/assets/img/folder/test.png']
        },
    ]),

I also tried like that:

    new CopyWebpackPlugin([
        {
            from: 'src/assets',
            to: 'assets',
            ignore: ['src/assets/img/folder/*']
        },
    ]),

Regarding the readme I think I am doing right.


Solution

  • New versions of CopyWebpackPlugin have changed the way of ignoring files.

    new CopyWebpackPlugin({
        patterns: [{
            from: defaultSourcePath,
            globOptions: {
                ignore: [
                    '**/css/my.css',
                    '**/js/my.js',
                    '**/index.html'
                ]
            }
        }]
    })