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

Allow use of contenthash along with templatehash #1065

Merged
merged 2 commits into from Oct 3, 2018
Merged

Allow use of contenthash along with templatehash #1065

merged 2 commits into from Oct 3, 2018

Conversation

sibiraj-s
Copy link
Contributor

@sibiraj-s sibiraj-s commented Oct 2, 2018

This allows to use contenthash which was removed in #1062 . Now when filename is provided with contenthash it will be internally replaced to templatehash

Fixes: #1033

Copy link

@pegiadise pegiadise left a comment

Choose a reason for hiding this comment

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

Great work. Thanks for this. I hope it gets merged.

index.js Outdated
// `contenthash` is introduced in webpack v4.3
// which conflicts with the plugin's existing `contenthash` method, hence
// hence is renmaed to `templatehash` to avoid such conflicts
const REGEXP_CONTENTHASH = /\[(?:(\w+):)?contenthash(?::([a-z]+\d*))?(?::(\d+))?\]/ig;

Choose a reason for hiding this comment

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

I think this could be simplified to:

      this.options.filename = this.options.filename.replace(REGEXP_CONTENTHASH, (match) => {
        return match.replace('contenthash', 'templatehash');
      });

No need for the verbose variable declaration and the if check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I thought of moving them both to the very top. hence assigned to a variable. Which I thought may be reusable in future.

index.js Outdated
@@ -99,6 +99,16 @@ class HtmlWebpackPlugin {
this.options.filename = path.relative(compiler.options.output.path, filename);
}

// `contenthash` is introduced in webpack v4.3
// which conflicts with the plugin's existing `contenthash` method, hence
// hence is renmaed to `templatehash` to avoid such conflicts

Choose a reason for hiding this comment

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

Typo and extra hence here 😸

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will fix, thanks 👍

index.js Outdated
// Allow to use [templatehash] as placeholder for the html-webpack-plugin name
// See also https://survivejs.com/webpack/optimizing/adding-hashes-to-filenames/
// From https://github.com/webpack-contrib/extract-text-webpack-plugin/blob/8de6558e33487e7606e7cd7cb2adc2cccafef272/src/index.js#L212-L214
const finalOutputName = childCompilationOutputName.replace(/\[(?:(\w+):)?templatehash(?::([a-z]+\d*))?(?::(\d+))?\]/ig, (_, hashType, digestType, maxLength) => {
const finalOutputName = childCompilationOutputName.replace(REGEXP_TEMPLATEHASH, (_, hashType, digestType, maxLength) => {

Choose a reason for hiding this comment

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

Again, maybe it's just me but I would prefer to see the regex directly here and not having to look for the verbose variable.

Copy link
Owner

Choose a reason for hiding this comment

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

I agree - it would be easier to read if we just copy the regexp into the replace

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay. Updated 👍

@jantimon jantimon merged commit 24e4f10 into jantimon:webpack-4 Oct 3, 2018
@sibiraj-s sibiraj-s deleted the patch-3 branch October 3, 2018 13:35
@sibiraj-s
Copy link
Contributor Author

Hi @jantimon After beta.1 few important changes were added, can we have another beta to test these out .

@jantimon
Copy link
Owner

Sure I'll try to release it this weekend :)

@lock lock bot locked as resolved and limited conversation to collaborators Nov 12, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants