You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I could fork it but I would rather have the option of specifying this in the angular-cli.json, it seems strange to me to have this as a hardcoded feature
Reacted by Alexander, Stoicho Monev, Val Neekman, Matus Moravcik, Eik Emil Bengtsson, Sander Hammelburg, Bohdan Kalynovskyi (Dan), David Burke, Rajesh Babu , Stepan Suvorov and 21 more
angular-cli is built to "just work" with as little options as possible. If you want more complex usage you should probably have your own webpack setup instead.
Imagine the config file if we would accept every single use case.
An addon system is in the plans and has been discussed in #1656.
Sure, I understand that we can't add settings for everything but when you default to this type of behavior it would be good to at least be able to turn it off. What is the time frame for this addon system? Why not just expose the webpack config directly like you do with karma and protractor?
Exactly, but for karma and protractor there is config files, why not webpack? I have nothing against defaults that make it "just work" for most people but it should still be possible to change thing using the configuration.
Our reason it this:
We push the files to a cdn using a inhouse system which we have to use. This system uses a config file where we define the file that should be put there as part of our build. It does not handle wildcards in the filename and because of this we can't use the production build and don't get the tree shaking and everything else.
I guess I have to do a workaround for this but it feels sad that the only options is forking or going the webpack route directly, whats the point of the cli then?
@fredrik-holmqvist I understand this is a need you have, but surely you understand that we could not predict that your in-house CDN has a problem with wildcards. The CLI doesn't aim to cover every scenario possible.
If this is a big need for your org I encourage you to make a PR to support such an option, preferably on the build command. Otherwise at the moment I'd say this is one of the lowest priority requests around.
But a workaround here seems much easier than that: have a script that globs your files in dist/ after a prod build, renames them to remove the hash, and does the same in index.html.
It's not an in-house CDN and it's not that it doesn't support wildcards. It's the way we version, we want it to be predictable so that teams can upgrade to a new version in a predictable way, without having to know any hashes, more like you version libraries on CDNs. And for this we would have liked for it to not touch the names of the files when you do a production build, but I get it, we are not really the core audience for this tool, to much custom stuff unfortunately
We have already made a workaround for this so this issues is resolved from our side
Reacted by Carlos Clemente, Roman Zabila, Massimiliano Kraus, Steven Lacks and michalhainc
@fredrik-holmqvist I've received another request for this, and tbh I think I closed this too soon. If more people want this, they wouldn't find the issue, nor work a PR to add it.
Reacted by Hadrien TOMA, bochove, Chrysostomos Kolovos, Alex Kent, Chris Skinner, Michael Treser, Jack Olsen, Sergey Sagan and Gökhan Öner
But cli pushed some unpredictable hashes into index.html so the option left to me is to use that index.html rather than html string. It's kind of hacky 'cause I need to read the html file and replace the strings. It would be much easier/faster to hard code if we can.
I found this working now, seems got added already with so many request :)
add --output-hashing none during build
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 So my build command looks like this:- ng build --prod --output-hashing none
Reacted by 陈仕豪, Oleg Postoev, WesDev, openHex, Diego Santiesteban, Jorge V, jody tate, Gabriel Giussi, Vincent, Matt Jhou (TW-PLAT/PROM-TD) and 38 more
Reacted by codeepic, Guruprasad J Rao and Thomas Champion
Reacted by WesDev, jody tate, Vincent, Matt Jhou (TW-PLAT/PROM-TD), Hadrien TOMA, Karl Smith, Mike Beach, Div-Codes, Frank Goortani, Ann Prokhorova and 8 more
I found this working now, seems got added already with so many request :)
add --output-hashing none during build
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
So my build command looks like this:- ng build --prod --output-hashing none
Reacted by Sheroze J, openHex and Muthusamy Jayaraman
@kevindqc With query string there's no guarantee that the files will be cached.
Squid for example used to have (I think it has changed) a default configuration that didn't cache dynamic content and query strings were considered to be dynamic content.
The last operation of the build command above is to overwrite the index.html with something like "index.dist-default.html" in your src and set all script sources without the hash like this...
Example of scripts In your index replacement file (index.dist-default.html or whatever): <script type="text/javascript" src="inline.js"></script> <script type="text/javascript" src="polyfills.js"></script> <script type="text/javascript" src="vendor.js"></script> <script type="text/javascript" src="main.js"></script>
Reacted by Herlon Aguiar, mbwilliamson, Rauno Kulla, Pavel Nuzhdin and Petar Nikolovski
IMHO, this solution provides the best of both worlds and end solution for many posters, as follows:
(1) ng build --prod --output-hashing none - deploy files with same name on each and every build which is desirable by many developers for SCM purposes (tracking, comparison, history etc.) and
(2) update webpack config to add hash query string in index.html - attaches a unique hash as a query string which, in most cases, will result in uniquely versioning your file in the browser cache so the browser reads the new version of the artifacts on each new deployment rather than reading it from cache.
However, it requires forking Angular CLI at the webpack config,the file at node_module/@angular/cli/models/webpack-configs/brower.js to add one configuration line to the new HtmlWebpackPlugin section (... ,hash: true // add }). To avoid a fork to Angular CLI, I would recommend a new option, to the effect of:
ng build --prod --output-hashing partial
where "partial" adds a hash query string but does not add a hash to files. The name of the option can be decided; having a configurable feature that blends both features above would avoid a fork, preserve SCM tracking of files, while also eliminate most caching issues, all of which are useful and seem to meet a requirement of a large population. Thank you.
Reacted by Adrián Mouly, Roger Senna, Chrysostomos Kolovos, Regis Silva, Janne Julkunen, Matthew-Hope Eland, WhistlerHusky, Adam Weber, Lars Jacobsson, auttaponshine and 19 more
Reacted by Nicolas Favaron, SmoillingCamel, pavelpribysh, Oskar Mossberg and Daniel Kucal
Any chance to reopen this issue for a solution like @dgecawich suggested? (move hash to query string) Or should we open a new issue?
I have a usecase that would need the same solution. A Piwik plugin tries to load the styles of our site at a later point but without a fixed filename it will already be gone. However, disabling the hashing completely will lead to trouble with the cache. Hash in the query string seems to have the best of both worlds.
Reacted by Andrii, Nicolas Favaron, Danijel Maksimovic and pavelpribysh
--output-hashing none works a treat. Nice that everyone on this post was notified and that it is now included in the docs. Oh wait, they weren't and it's not. I know - we'll add a great feature in that everyone was requesting but won't tell anyone or put it in the docs. Now that sounds like what devs would do... 👍
Reacted by Tim A. Perez, Alexandru, Yuri Artemenko, Dawid Zbiński, coultonluke, Zachary Boyd, Petar Nikolovski, Chris Scheufele, El Pupi, Deepak Chandani and 2 more
Reacted by idchlife, B Abhineeth Bhat, Kalpesh, Joel Mukuthu, Petar Nikolovski and El Pupi
@lihuabest Is there a way to replace the hash number with a specified version number? Something like this: <script type="text/javascript" src="main.bundle.js?version=1.2.0"></script>
Reacted by pavelpribysh, Jihad MOTII, fstbraz, FarhadAdeli, 127.0.0.1 and Michael Fischer
Activity
grizzm0 commentedon Oct 19, 2016
No there is not.
You could fork the repo and edit
./angular-cli/packages/angular-cli/models/webpack-build-production.tsto remove it if you really want to.filipesilva commentedon Oct 23, 2016
^ what @grizzm0 said 💃
fredrik-holmqvist commentedon Oct 24, 2016
I could fork it but I would rather have the option of specifying this in the angular-cli.json, it seems strange to me to have this as a hardcoded feature
grizzm0 commentedon Oct 24, 2016
angular-cli is built to "just work" with as little options as possible. If you want more complex usage you should probably have your own webpack setup instead.
Imagine the config file if we would accept every single use case.
An addon system is in the plans and has been discussed in #1656.
fredrik-holmqvist commentedon Oct 24, 2016
Sure, I understand that we can't add settings for everything but when you default to this type of behavior it would be good to at least be able to turn it off. What is the time frame for this addon system? Why not just expose the webpack config directly like you do with karma and protractor?
grizzm0 commentedon Oct 24, 2016
You could say that about anything that is enabled by default. What's the reason you want to disable the hashing for?
fredrik-holmqvist commentedon Oct 24, 2016
Exactly, but for karma and protractor there is config files, why not webpack? I have nothing against defaults that make it "just work" for most people but it should still be possible to change thing using the configuration.
Our reason it this:
We push the files to a cdn using a inhouse system which we have to use. This system uses a config file where we define the file that should be put there as part of our build. It does not handle wildcards in the filename and because of this we can't use the production build and don't get the tree shaking and everything else.
I guess I have to do a workaround for this but it feels sad that the only options is forking or going the webpack route directly, whats the point of the cli then?
filipesilva commentedon Nov 2, 2016
@fredrik-holmqvist I understand this is a need you have, but surely you understand that we could not predict that your in-house CDN has a problem with wildcards. The CLI doesn't aim to cover every scenario possible.
If this is a big need for your org I encourage you to make a PR to support such an option, preferably on the build command. Otherwise at the moment I'd say this is one of the lowest priority requests around.
But a workaround here seems much easier than that: have a script that globs your files in
dist/after a prod build, renames them to remove the hash, and does the same in index.html.fredrik-holmqvist commentedon Nov 2, 2016
It's not an in-house CDN and it's not that it doesn't support wildcards. It's the way we version, we want it to be predictable so that teams can upgrade to a new version in a predictable way, without having to know any hashes, more like you version libraries on CDNs. And for this we would have liked for it to not touch the names of the files when you do a production build, but I get it, we are not really the core audience for this tool, to much custom stuff unfortunately
We have already made a workaround for this so this issues is resolved from our side
filipesilva commentedon Nov 3, 2016
@fredrik-holmqvist I've received another request for this, and tbh I think I closed this too soon. If more people want this, they wouldn't find the issue, nor work a PR to add it.
chouclee commentedon Nov 7, 2016
Same request, my use case is server side rendering. I need to replace several variables in html string (preferably, just like React way).
But cli pushed some unpredictable hashes into index.html so the option left to me is to use that index.html rather than html string. It's kind of hacky 'cause I need to read the html file and replace the strings. It would be much easier/faster to hard code if we can.
8 remaining items
shoagraw commentedon Apr 19, 2017
I found this working now, seems got added already with so many request :)
add --output-hashing none during build
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
So my build command looks like this:- ng build --prod --output-hashing none
shoagraw commentedon Apr 19, 2017
I found this working now, seems got added already with so many request :)
add --output-hashing none during build
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
So my build command looks like this:- ng build --prod --output-hashing none
kevindqc commentedon Apr 25, 2017
I need filenames that don't change but also would like to have a hash to invalidate cache. Is there a reason the hash can't be on the query string?
For example, this gets injected into my index.html:
How about:
grizzm0 commentedon Apr 26, 2017
@kevindqc With query string there's no guarantee that the files will be cached.
Squid for example used to have (I think it has changed) a default configuration that didn't cache dynamic content and query strings were considered to be dynamic content.
timperez-weather commentedon Apr 27, 2017
Temporary solution...
In your package.json > scripts:
"build": "ng build --prod && mv dist/main.*.bundle.js dist/main.js && mv dist/vendor.*.bundle.js dist/vendor.js && mv dist/inline.*.bundle.js dist/inline.js && mv dist/polyfills.*.bundle.js dist/polyfills.js && cp -f src/index.dist-default.html dist/index.html"The last operation of the build command above is to overwrite the index.html with something like "index.dist-default.html" in your src and set all script sources without the hash like this...
Example of scripts In your index replacement file (index.dist-default.html or whatever):
<script type="text/javascript" src="inline.js"></script><script type="text/javascript" src="polyfills.js"></script><script type="text/javascript" src="vendor.js"></script><script type="text/javascript" src="main.js"></script>lihuabest commentedon Jul 5, 2017
if you want build file like
<script type="text/javascript" src="inline.bundle.js?908517239e551bfc4e9b"></script>first set build line like
ng build --prod --output-hashing none
second update webpack config,the file at node_module/@angular/cli/models/webpack-configs/brower.js
update HtmlWebpackPlugin config,
new HtmlWebpackPlugin({ ... hash: true // add }),this is just i find...hopeful official solution
dgecawich commentedon Aug 1, 2017
I tested the above solution and it works well, resulting in the following.
IMHO, this solution provides the best of both worlds and end solution for many posters, as follows:
(1) ng build --prod --output-hashing none - deploy files with same name on each and every build which is desirable by many developers for SCM purposes (tracking, comparison, history etc.) and
(2) update webpack config to add hash query string in index.html - attaches a unique hash as a query string which, in most cases, will result in uniquely versioning your file in the browser cache so the browser reads the new version of the artifacts on each new deployment rather than reading it from cache.
However, it requires forking Angular CLI at the webpack config,the file at node_module/@angular/cli/models/webpack-configs/brower.js to add one configuration line to the new HtmlWebpackPlugin section (... ,hash: true // add }). To avoid a fork to Angular CLI, I would recommend a new option, to the effect of:
ng build --prod --output-hashing partial
where "partial" adds a hash query string but does not add a hash to files. The name of the option can be decided; having a configurable feature that blends both features above would avoid a fork, preserve SCM tracking of files, while also eliminate most caching issues, all of which are useful and seem to meet a requirement of a large population. Thank you.
magnattic commentedon Feb 8, 2018
Any chance to reopen this issue for a solution like @dgecawich suggested? (move hash to query string) Or should we open a new issue?
I have a usecase that would need the same solution. A Piwik plugin tries to load the styles of our site at a later point but without a fixed filename it will already be gone. However, disabling the hashing completely will lead to trouble with the cache. Hash in the query string seems to have the best of both worlds.
chrisj-skinner commentedon Apr 30, 2018
--output-hashing none works a treat. Nice that everyone on this post was notified and that it is now included in the docs. Oh wait, they weren't and it's not. I know - we'll add a great feature in that everyone was requesting but won't tell anyone or put it in the docs. Now that sounds like what devs would do... 👍
yurart commentedon May 24, 2018
Thanks! It's a really useful feature
abbymrs commentedon Jun 28, 2018
@lihuabest Is there a way to replace the hash number with a specified version number? Something like this:
<script type="text/javascript" src="main.bundle.js?version=1.2.0"></script>Vitzkrieg commentedon May 31, 2019
in angular.json
angular-automatic-lock-bot commentedon Sep 9, 2019
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.