loader-utils icon indicating copy to clipboard operation
loader-utils copied to clipboard

Feature: add compiler output options support for hash

Open aarefiev opened this issue 6 years ago • 1 comments

Good day, guys!

Yesterday I worked on configuring webpack for my own project and I found that I can't use the same output filename settings for all loaders. Especially, for file-loader.

Here is the part of webpack.config.js:

output: {
  path: outputPath,
  filename: '[name].[contenthash].js',
  publicPath: `${publicPath}/`,
  hashDigestLength: 8
},
module: {
  rules: [
    {
      test: /\.(png|jpg|gif|svg|cur)(\?v=\d+\.\d+.\d+)?$/,
      include: paths.src,
      use: [
        {
          loader: 'file-loader',
          options: {
            name: '[name].[hash].[ext]',
            publicPath: `${publicPath}/`
          }
        }
      ]
    }
  ]
},
plugins: [
  htmlWebpackPlugin,
  new MiniCssExtractPlugin({
    filename: '[name].[contenthash].css'
  })
]

After compilation I found that the hash part of name of extracted css and bundled files are truncated, but all other assets that I uploaded as is with file-loader are not truncated. As solution, I should pass maxLength to options.name (in format [name].[hash:8].[ext]) and it will work as I expected. I think it is not good because I should pass the same settings for each loader, maybe is better to support compiler settings as it support MiniCssExtractPlugin.

What you think about it?

aarefiev avatar Dec 20 '18 08:12 aarefiev

CLA assistant check
All committers have signed the CLA.

jsf-clabot avatar Dec 20 '18 08:12 jsf-clabot