Skip to content
This repository has been archived by the owner on Mar 17, 2021. It is now read-only.

Feature: compiler output options support for hash #313

Closed
aarefiev opened this issue Dec 21, 2018 · 1 comment
Closed

Feature: compiler output options support for hash #313

aarefiev opened this issue Dec 21, 2018 · 1 comment

Comments

@aarefiev
Copy link

Hi!.

Thanks for great loader. It's really save my time :).

Some days ago 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. 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?
I know that you using loader-utils for process files, that's why I submitted my request there (webpack/loader-utils#120).

I will be glad to hear what you think about it. Thanks :')

@alexander-akait
Copy link
Member

alexander-akait commented Dec 21, 2018

@aarefiev please use issue template in future, issues without template was closed and ignored

Yep, it is make sense, we need fix it on loader-utils for better future integration, so it is not related to file-loader, because other loaders also use this library for hashes and have same problem. Please create issue in loader-utils and attach link to the PR. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants