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

No hash in name in production build

Open fredrik-holmqvist opened this issue 10 years ago • 31 comments

Hi

I am wondering if there is a setting to disable the hash in the name for main bundle and style bundle for production builds?

/Fredrik

fredrik-holmqvist avatar Oct 19 '16 09:10 fredrik-holmqvist

No there is not.

You could fork the repo and edit ./angular-cli/packages/angular-cli/models/webpack-build-production.ts to remove it if you really want to.

grizzm0 avatar Oct 19 '16 09:10 grizzm0

^ what @grizzm0 said 💃

filipesilva avatar Oct 23 '16 15:10 filipesilva

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

fredrik-holmqvist avatar Oct 24 '16 12:10 fredrik-holmqvist

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.

grizzm0 avatar Oct 24 '16 15:10 grizzm0

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?

fredrik-holmqvist avatar Oct 24 '16 18:10 fredrik-holmqvist

You could say that about anything that is enabled by default. What's the reason you want to disable the hashing for?

grizzm0 avatar Oct 24 '16 19:10 grizzm0

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 avatar Oct 24 '16 19:10 fredrik-holmqvist

@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.

filipesilva avatar Nov 02 '16 16:11 filipesilva

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

fredrik-holmqvist avatar Nov 02 '16 20:11 fredrik-holmqvist

@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.

filipesilva avatar Nov 03 '16 18:11 filipesilva

Same request, my use case is server side rendering. I need to replace several variables in html string (preferably, just like React way).

<script>
    window.__INITIAL_STATE__ = ${JSON.stringify(initialState)}
</script>

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.

chouclee avatar Nov 07 '16 20:11 chouclee

Sorry, I forgot to reopen this on my last comment!

filipesilva avatar Nov 21 '16 13:11 filipesilva

How about this:

1. A flag to (enable / disable) hashing 2. An include list - files & wildcards to hash 3. An exclude list - files & wildcards to exclude

The above may include the assets directory as well. (for when hosting on CDN) The default can be left as whatever behavior we have today.

Those who don't need hashing, simply turn it off.

un33k avatar Dec 02 '16 23:12 un33k

@grizzm0 One reason not to hash - would be to use an external tool (e.g. gulp plugin) to hash everything, even the images, especially if you are going to host the project on let's say AWS S3/CloudFront.

Now, if NG-CLI took care of all the files (*.png, *.gif, etc.) in the assets directory as well, then one could say angular-cli is built to "just work".

However, as it stands, since there is no non-forky way to disable the hashing, any external hashing tools will create ugly double-hashed names for the .js/.css/.map/.gz files that NG-CLI already hashed. But the images, for example, will have single-hash in their names.

One might say, well that is not a big deal. However, since ng-cli is a community-driven project, we might want to make it work elegantly and for everyone.

Options with default values may be the right approach here.

un33k avatar Dec 06 '16 17:12 un33k

BTW this is easy to do on your side as a part of the deployment:

$ mv inline.*.bundle.js inline.bundle.js will get rid of the hash

then in your index.html have <script src="build/js/inline.bundle.js"></script>

+1 to a flag, though

mmoravcik avatar Dec 09 '16 18:12 mmoravcik

I would also need this option. I include the js files in a CMS and don't want to update the html snippet every time I make a new release of my angular 2 application.

SSilence avatar Dec 15 '16 13:12 SSilence

The reason we are using angular-cli is that it eliminates configuration process and provides the same workflow for each project. It just does not make sense to repeat all configuration and build steps with webpack or gulp or rollup, because angular-cli already does what we need (AOT + Webpack).

Currently we have to wrap angular-cli with gulp to remove hashes and unused files, it is silly job.

kemsky avatar Jan 09 '17 14:01 kemsky

+1 to add this feature.

FerGabPereira avatar Jan 09 '17 20:01 FerGabPereira

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 avatar Apr 19 '17 00:04 shoagraw

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 avatar Apr 19 '17 00:04 shoagraw