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

feat(build): allow output hashing to be configured #3885

Merged
merged 4 commits into from Jan 10, 2017
Merged

feat(build): allow output hashing to be configured #3885

merged 4 commits into from Jan 10, 2017

Conversation

clydin
Copy link
Member

@clydin clydin commented Jan 6, 2017

This allows the output filename hashes to be configured during a build via a new build command option --output-hashing. There are four possible values:

  • none: no hashing performed
  • media: only add hashes to files processed via [url|file]-loaders
  • bundles: only add hashes to the output bundles
  • all: add hashes to both media and bundles

none is the default for the development target.
all is the default for the production target.

Fix #2774


const hashFormats: { [option: string]: any } = {
'none': { chunk: '', extract: '', file: '[name]' },
'media': { chunk: '', extract: '', file: '[hash:20]' },
Copy link

Choose a reason for hiding this comment

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

hashlength note: I think a 20 character long hash is unnecessary and make it much more less human readable. 6 would be much better.

media (file) template format note: as stated in #3871 (comment). sky-bg.jpg becomes 8bcfb98e274f484ebac02d81670b7e4c.jpg with '[hash:20]'. Don't you think [name].[hash:20] would be more ideal? Looking at 8bcfb98e274f484ebac02d81670b7e4c.jpg have absolutely no idea which image it is, that is a problem is think.

Copy link
Member Author

@clydin clydin Jan 7, 2017

Choose a reason for hiding this comment

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

20 is the webpack default and the existing tests rely on it so I went with it for consistency.
Personally I'd prefer a small decrease in human readability in exchange for a lower chance of collision. Especially considering they're not intended to be overly human readable. (we have dev builds for that.)
How about something in the middle: 12?
You're example is actually [hash:32] or just [hash] when using the file-loader. Oddly, [hash] means different things in different places in webpack and the defaults don't seem to carry over either.
I agree on the name inclusion as it would be consistent with the others but was hesitant to change the existing paradigm without a consensus.

@filipesilva thoughts?

Copy link

Choose a reason for hiding this comment

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

How about something in the middle: 12?

Sounds good to me if you dont mind also editing the test cases.

I agree on the name inclusion as it would be consistent with the others but was hesitant to change the existing paradigm without a consensus.

Lets get a green light from one of the maintainers. File- and url-loader should emit a filename containing [name].[hash:12] or [name].[hash:20] for consistency and human readability.

Copy link
Contributor

Choose a reason for hiding this comment

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

Regarding hash size, I think it's better to be consistent with the rest of the hashes already present so 20 sounds good to me.

The question of including the name is less obvious for me though. Having the name would be a change in the previous behaviour, but if we look at it with fresh eyes I think it's simply a better option since now everything that's processed follows the same pattern of [name].[hash].ext.

Some users are confused by the multitude of files suddenly propping up in their dist folder and that would help them make sense of it. It also adds a bit more collision protection.

So my vote goes for [name].[hash:20]. I think [name] should be in the common config instead of here though (like the others).

Copy link
Contributor

@filipesilva filipesilva left a comment

Choose a reason for hiding this comment

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

Tests are missing as you mentioned but I think this is a really good PR.

It adds functionality users have been asking for, expands upon the fix itself to offer granular support and eliminates code duplication we had before due to hardcoded values.

Great work @clydin and @tsm91!

PS.: I hope you don't mind but I edited the PR comment to include the issue this PR fixes.

new ExtractTextPlugin({filename: '[name].bundle.css'})
]
};
return { };
Copy link
Contributor

Choose a reason for hiding this comment

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

Gotta say I love the fact that this change makes the dev config dispensable. Can you remove it from the webpack merge procedure as well?

Copy link
Member Author

@clydin clydin Jan 7, 2017

Choose a reason for hiding this comment

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

I was planning on making a PR that adds NamedModulesPluginto dev builds to support HMR. Can do it another way though (e.g., only when HMR is enabled), if you'd prefer the file removed.

Copy link
Contributor

Choose a reason for hiding this comment

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

If there's a reason for the file to exist then it shouldn't be removed. I didn't know of NamedModulesPlugin but a quick google search made me think it's main use is to have good names in HMR, is that correct? If so, it makes sense to have it automatically with HMR, yes.

Copy link
Member Author

@clydin clydin Jan 7, 2017

Choose a reason for hiding this comment

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

That's the reason I was going to add it. But it also stabilizes the module id's between builds which has benefits for cache busting. The hash won't change due to webpack module id renumbering. Nothing bad happens without it; the hash just might change more often than needed. And this isn't really relevant for HMR and probably not for dev builds in general.
For production builds there is HashedModuleIdsPlugin, which hashes the names to obfuscate the file path details.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd be interested in such a PR then. Ping me if you end up doing it and I will review it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also wonder if that would help with the reload times tbh. It sounds like it might do away with rebuilding some modules due to id changes.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure. But I'll see if I can put a PR together.
Also, I was looking through webpack-config.ts where the merging happens and to cleanly remove the dev config will require some refactoring (which the file could probably use either way) so it might be best to leave it for a followup PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

I want to refactor the way we pass options down to the webpack config anyway, so I can do that at the time. It's getting messy as is.


const hashFormats: { [option: string]: any } = {
'none': { chunk: '', extract: '', file: '[name]' },
'media': { chunk: '', extract: '', file: '[hash:20]' },
Copy link
Contributor

Choose a reason for hiding this comment

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

Regarding hash size, I think it's better to be consistent with the rest of the hashes already present so 20 sounds good to me.

The question of including the name is less obvious for me though. Having the name would be a change in the previous behaviour, but if we look at it with fresh eyes I think it's simply a better option since now everything that's processed follows the same pattern of [name].[hash].ext.

Some users are confused by the multitude of files suddenly propping up in their dist folder and that would help them make sense of it. It also adds a bit more collision protection.

So my vote goes for [name].[hash:20]. I think [name] should be in the common config instead of here though (like the others).

@filipesilva
Copy link
Contributor

Regarding #3853, it actually asks for something slightly different. That request is for scripts/styles marked as lazy to never have hashes.

Personally I don't know of a way to exclude some files from having the hash, nor think it needs to be together in this PR. But if any of you know a way to do it I'd appreciate being pointed in the right direction and then I can make a followup PR with that fix (or you can, if you want to).

@aegyed91
Copy link

aegyed91 commented Jan 9, 2017

@filipesilva im not sure how this lazy option works in angular-cli, wanted to search the readme.md but got 0 results for the word lazy :D. Only do lazy route module loads with loadChildren, but that is a different story.

What i know is the AOT build output files will get hashed or non hashed the same way. It doesnt matter if its an AOT or non AOT build, what matters is if it is a dev or prod environment build: https://github.com/angular/angular-cli/blob/master/packages/angular-cli/models/webpack-config.ts#L53-L58

Just did an aot build on a fork with cache-bust disabled ng build --aot --prod --no-sourcemap --verbose --dcb and got the desired output: http://i.imgur.com/prcUbG0.png . Ofc in my fork the url-, file-loader still generates hashed media files.

.. nor think it needs to be together in this PR

I think this PR should be merged and get into beta.25.

@filipesilva
Copy link
Contributor

@tsm91 that lazy loaded scripts/styles functionality is actually a different thing than lazy loaded routes. See #3401 for details about them.

@aegyed91
Copy link

@filipesilva https://github.com/angular/angular-cli/pull/3402/files i wonder why there is no README.md file in the changes. This feature is not even documented.

@clydin clydin changed the title [WIP]feat: allow output hashing to be configured feat(build): allow output hashing to be configured Jan 10, 2017
@filipesilva
Copy link
Contributor

@tsm91 I didn't add them at the time, which was really a bad choice.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 11, 2019
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.

No hash in name in production build
5 participants