Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom generated filename with Angular Cli

With Angular-cli the builded filename is main.[hash].bundle.js when use ng build -prod Is it possible to remove the hash form this filename. So just main.bundle.js?

like image 888
sneeky Avatar asked Sep 27 '16 07:09

sneeky


3 Answers

It's now supported via a command option as of beta.25.

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.

More details here.

like image 83
Recep Avatar answered Oct 21 '22 10:10

Recep


I added the following script element for production build in the package.json file.

"scripts": {
    "prod" : "ng build --prod --output-hashing=none --base-href=./"
}

then running

npm run prod

would build the dist folder without hash and also includes the ./ as base-href so that files are loaded relative to current directory.

like image 11
Krishna Vedula Avatar answered Oct 21 '22 08:10

Krishna Vedula


As per my understanding the hash is used for production build so that one wont run into browser cache issues, and the users wont have to clear cache before using the new deployment.

I doubt that angular-cli team would give us an option to configure that, we have to wait to check that.

Meanwhile if you want to customize your build process you may build the webpack config yourself.

Also, the CLI team has indicated that there will be a few webpack plugins which will help in creating own webpack configuration. Checkout here.

More details here, WEBPACK: AN INTRODUCTION.

like image 8
Madhu Ranjan Avatar answered Oct 21 '22 08:10

Madhu Ranjan