Webpack Exclude a specific file

user7768004 picture user7768004 · Jun 5, 2017 · Viewed 53.6k times · Source

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

...

Answer

Lee Han Kyeol picture Lee Han Kyeol · Jun 6, 2017

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