johnagan / clean-webpack-plugin

A webpack plugin to remove your build folder(s) before building
MIT License
1.96k stars 135 forks source link

Can not use !negative pattern to exclude directories in multiple webpack configs #158

Closed popolan1986 closed 5 years ago

popolan1986 commented 5 years ago

Issue description or question

I fail to use !negative pattern to exclude directories in multiple webpack configs to prevent this plugin from deleting nested paths. After building, the nested directory abc is deleted.

Webpack Config

const {CleanWebpackPlugin} = require('clean-webpack-plugin');

module.exports = [
  {
    entry: 'src/index.js',
    output: {
        path: path.resolve(__dirname, 'dist')
    }
    plugins: [
       new CleanWebpackPlugin({
          cleanOnceBeforeBuildPatterns: ['**/*', '!abc/**/*'],
       })
    ]
  },
  {
    entry: 'src/abc/abc.js',
    output: {
        path: path.resolve(__dirname, 'dist', 'abc')
    }
    plugins: [
       new CleanWebpackPlugin({
         cleanOnceBeforeBuildPatterns: ['**/*', '!def/**/*'],
       })
    ]
  },
  {
    entry: 'src/def/def.js',
    output: {
        path: path.resolve(__dirname, 'dist', 'abc', 'def')
    }
    plugins: [
       new CleanWebpackPlugin()
    ]
  }
];

Environment

 System:
    OS: Windows 10
    CPU: (8) x64 Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz
    Memory: 398.06 MB / 15.91 GB
  Binaries:
    Node: 10.13.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.13.0 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 6.4.1 - C:\Program Files\nodejs\npm.CMD
sirockin commented 5 years ago

@popolan1986 I ran into the same problem and replaced the '!excluded_dir/**/*' pattern with '!excluded_dir/**'. That does seem to work.

popolan1986 commented 5 years ago

@sirockin , I know why the nested directory is deleted. abc/**/* matches abc's nested directories but not itself so the clean plugin deletes abc. I can use Braced section to exclude abc directory like this !abc{, **/*} (= !abc or !abc/**/*).

chrisblossom commented 5 years ago

@popolan1986 is your issue resolved? Can I close this?

popolan1986 commented 5 years ago

@popolan1986 is your issue resolved? Can I close this?

Yes, you can.