angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Removing hash from Webpack bundle

Open Trevald opened this issue 10 years ago • 17 comments

Is there a way to modify settings for the webpack bundles to remove the hash from the js-files and the script-tags generated in index.html?

Trevald avatar Aug 25 '16 09:08 Trevald

those are used for cache breaking. You should set the headers to have long cache times and keep the hashes :)

ghost avatar Aug 28 '16 01:08 ghost

I know, and I would love to keep 'em. But I'm delivering my bundle to a back-end developer who doesn't use the generated index.html but rather only wants to replace the old bundle with a new one without needing to change the hash.

Trevald avatar Aug 28 '16 18:08 Trevald

Could you just write a script to do that for you?

deebloo avatar Aug 28 '16 18:08 deebloo

@deebloo You could probably write a gulp-script that does that but it seems to me that that would be having two steps in the process that could be reduced to zero steps, adding hash and removing has. Instead of just not adding hash.

Thanks for the tip but the question remains, even though apparently badly put, is it possible to change the bundle process to not adding hash rather than is there a way to remvove hash.

I like the simplicity of the bundle process with CLI, I need to do absolutely nothing. But here I am in a situation wanting to do something and it just seems to me that this little change should be an ever so simple task.

Trevald avatar Aug 28 '16 20:08 Trevald

If you use ng build without the --prod flag you shouldn't get any hashes.

filipesilva avatar Sep 20 '16 17:09 filipesilva

Does --prod only add the hash and use the environments.prod file? If not, then this isn't a good solution, because they would want the other advantages of using --prod such as the tree-shaking and uglifying.

bryanjjohnson avatar Sep 26 '16 20:09 bryanjjohnson

Any idea or option to remove hash? I have the same issue.

t2d-ev avatar Oct 17 '16 03:10 t2d-ev

We ended up adding these to our build script: ng build -prod mv dist/main..bundle.js dist/main.bundle.js mv dist/main..bundle.js.gz dist/main.bundle.js.gz mv dist/styles..bundle.js dist/styles.bundle.js mv dist/styles..bundle.js.gz dist/styles.bundle.js.gz

bryanjjohnson avatar Oct 17 '16 18:10 bryanjjohnson

Thanks, that's helpful @bryanjjohnson .

@filipesilva / @deebloo : removing --prod has for sure not the same effect... We all have a specific and valid reason why we want to make a prod bundling, but don't want the hash. That shall be definitely an option in the angular-cli. Or maybe you shall allow to provide a Webpack config which could overwrite some default option. I see other issues which are raised, simply because the current configuration possibilities are to strict. Which is a paradox, because Webpack is actually extremely flexible in itself.

Please reopen the issue and consider this feature request.

0cv avatar Nov 08 '16 19:11 0cv

Hash removal option being tracked in https://github.com/angular/angular-cli/issues/1833

filipesilva avatar Nov 21 '16 13:11 filipesilva

Any update on if this will be implemented? I would also need to prevent the hash generation in the name for similar reasons

phil-ioniq avatar Jan 03 '17 18:01 phil-ioniq

any updates?

FerGabPereira avatar Jan 09 '17 20:01 FerGabPereira

Sorry I linked the wrong issue, here is where it's being tracked: https://github.com/angular/angular-cli/issues/2774

filipesilva avatar Jan 09 '17 22:01 filipesilva

Closed on https://github.com/angular/angular-cli/pull/3885 try using: ng build --prod --output-hashing none

dmesa avatar Feb 12 '17 07:02 dmesa

ng build --prod --output-hasing media/none/bundles

output-hashing --output-hashing (aliases: -oh)

Define the output filename cache-busting hashing mode.

Values: none, all, media, bundles

https://github.com/angular/angular-cli/wiki/build

SSAT avatar Mar 02 '18 16:03 SSAT

Is it possible to add the hashing value as a url parameter? eg :

<script src="main.bundle.js?v=8ce0183eeaa599bafb462"></script>

That way the cache busting stays intact and we have the benefit of static named files?

WebStew avatar Jun 07 '18 11:06 WebStew

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.