Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional filename in webpack config output

my current webpack output config is as follows:

output: {
    path: PATHS.build,
    filename: '/[name].[chunkhash].js',
    chunkFilename: '/[chunkhash].js'
}

However, I have one entry file (custom.js) that I don't want to add [chunkhash] suffix. all others I do want to add the chuckhash suffix after the file name. Essentially:

if (name is 'custom') {
    filename: '/[name].js'
} else {
    filename: '/[name].[chunkhash].js'
}

How can I achieve this?

like image 219
jasan Avatar asked Oct 14 '16 05:10

jasan


2 Answers

From https://webpack.js.org/configuration/output/#output-filename:

module.exports = {

  //...
  output: {
    filename: ({ chunk: { name } }) => {
      return name === 'main' ? '[name].js': '[name]/[name].js';
    },
  }
};
like image 154
Kevin Lee Avatar answered Oct 11 '22 15:10

Kevin Lee


You can easily do that (webpack 4.x):

output: {
    filename: '[name].js',
    chunkFilename: (arg) => {
        if (arg.chunk.name == "vendor") {
            return '[name].[chunkhash].js';
        }
        return '[name].js';
    } ,
    publicPath: `/${common.APP_ROOT}/`
},
like image 33
Xalisys Avatar answered Oct 11 '22 16:10

Xalisys