CopyWebpackPlugin - ignore a folder

让人想犯罪 __ 提交于 2020-06-27 10:34:07

问题


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.


回答1:


Try this:

ignore: ['img/folder/**/*']

This will not copy the entire img/folder.

Remember to clear your destination folder before running your webpack.




回答2:


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'
            ]
        }
    }]
})


来源:https://stackoverflow.com/questions/56670264/copywebpackplugin-ignore-a-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!