user8570495
user8570495

Reputation: 1835

how to implement a custom post-build process for cli "ng build --prod"?

I have an ng2 app nested in a .NET MVC parent app. I configured this structure to support CLI. "ng build --dev" worked as expected. I simply copied the files that the build process inserted at the bottom of index.html and pasted those to the bottom of my Master.cshtml page. The final app runs as expected. However, I'm encountering an issue with "ng build --prod". This process generates js bundle files into the dist dir with the following file name format:

polyfills.b1706c7adb46ed3216b9.bundle

Is there any need to have the numbers in the middle of the bundle.js names? As an experiment, I removed these numbers from the filenames of the files generated by "ng build --prod" and kept the static script refs on my Master.cshtml: "./dist/inline.bundle.js", etc, and the app worked as expected.

I'm thinking that the easiest post-build process would be to simply generate a script to remove the numbers from the filenames. Does this seem like a reasonable approach? How would I create a post-build process for this?

Upvotes: 0

Views: 3320

Answers (2)

Vlad
Vlad

Reputation: 8572

How is about using npm scripts?

e.g.

"build": "ng build --prod",
"postbuild": "your commands here after building prod version"

Upvotes: 1

Andrei
Andrei

Reputation: 1216

read up on some details here the main use of the hash is for client side caching. If that file has been changed the hash will change and force the browser to reload the file; however, if the file has not been changed it can speed up the process using browser cache. Generally I don't see a reason to ever remove the file hash but you can read the documentation from webpack but you can change the process within the web pack file to disable hashing of files.

Upvotes: 1

Related Questions