Search code examples
javascriptreactjswebpackwebpack-2

Webpack Exclude a specific file


I have this code In my webpack.config.prod.js and I was wondering how do I exclude all json except one in a specific path like src/configs/configs

exclude: [
  /\.html$/,
  /\.(js|jsx)$/,
  /\.css$/,
  /\.json$/,
  /\.bmp$/,
  /\.gif$/,
  /\.jpe?g$/,
  /\.png$/,
],
loader: require.resolve('file-loader'),
options: {
  name: 'static/media/[name].[hash:8].[ext]',
}

...

Solution

  • According to the Webpack documentation, you can do something like this.

    exclude: {
      test: [
        /\.html$/,
        /\.(js|jsx)$/,
        /\.css$/,
        /\.json$/,
        /\.bmp$/,
        /\.gif$/,
        /\.jpe?g$/,
        /\.png$/,
      ],
      exclude: [
        'src/configs/configs/your.json'
      ]
    }