Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: add compiler output options support for hash #120

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

aarefiev
Copy link

@aarefiev aarefiev commented Dec 20, 2018

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?

@jsf-clabot
Copy link

jsf-clabot commented Dec 20, 2018

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need implement api for hash* options for loader api, feel free to open issue or better send a PR

@@ -64,12 +64,18 @@ function interpolateName(loaderContext, name, options) {
}
}
let url = filename;
const compilationOutputOptions = loaderContext._compilation && loaderContext._compilation.outputOptions || {};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is private properties and don't use their, you need open issue in webpack with feature request provide this option throw api

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@evilebottnawi thanks, i will do it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aarefiev good news, thanks for helping

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aarefiev can you create issue so that we don't lose this problem if it require time?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Successfully merging this pull request may close these issues.

3 participants