Webpack Config - Retrieving [name] as a variable in mini-css-extract-plugin

Viewed 348

I am trying to conditionally set filenames based on the [name] for my JS and CSS files. My webpack setup looks like the code below. In documentations for output (https://webpack.js.org/configuration/output/#outputfilename), it shows that the [name] can be accessed by "pathData.chunk.name". I'd also like to do the same for my CSS files inside the MiniCssExtractPlugin, but cannot find out what variable the [name] is being stored in.

Can anyone shed some light?

Thanks so much in advance! Jenna

module.exports = {
  ...
  output: {
    filename: (pathData) => {
      return pathData.chunk.name === 'main' ? '[name].js' : '[name]/[name].js';
    },
  },
  ...
  plugins: [
    ...
    new MiniCssExtractPlugin({
      filename: chunk.name ? '[name].css' : '[name].' + thisConfig['version'] + '.css',
      chunkFilename: '[id].css',
    }),
  ]


0 Answers
Related