Answer the question
In order to leave comments, you need to log in
How to solve the error when reloading angular/webpack chunks from the cache when the server has been updated?
I get an error when I update the prod server. After clearing the cache, this goes away, but how to solve this problem?
error photo -> prnt.sc/26k942n
ChuncLoadError
Package.json
"scripts": {
"ng": "ng",
"start": "cross-env NODE_ENV=dev webpack-dev-server --port=4200",
"build": "npm run clean && webpack",
"build:dev": "cross-env NODE_ENV=dev npm run build --sourcemap --aot --vendor-chunk --common-chunk --delete-output-path --buildOptimizer",
"build:test": "cross-env NODE_ENV=test npm run build --sourcemap --aot --vendor-chunk --common-chunk --delete-output-path --buildOptimizer",
"build:prod": "cross-env NODE_ENV=prod npm run build --aot",
"clean": "npm cache clean --force && npm run rimraf -- dist",
"rimraf": "rimraf",
"test": "ng test",
"lint": "ng lint",
"e2e": "protractor ./protractor.conf.js",
"pree2e": "webdriver-manager update --standalone false --gecko false --quiet"
},
output: {
path: path.join(process.cwd(), "dist"),
chunkFilename: `[name].[hash].chunk.js`,
filename: `[name].[hash].bundle.js`,
crossOriginLoading: false
},
Answer the question
In order to leave comments, you need to log in
Helped in webpack to put in output.
Replaced hash with contenthash (you can also use chunchash).
To optimize on Dev, I do not make this option, since it takes more time to build the contenthash
function generateOutputParams() {
if (ENV === 'dev') {
return {
path: path.join(process.cwd(), "dist"),
chunkFilename: `[name].[hash].chunk.js`,
filename: `[name].[hash].bundle.js`,
crossOriginLoading: false
}
}
return {
path: path.join(process.cwd(), "dist"),
chunkFilename: `[name].[contenthash].chunk.js`,
filename: `[name].[contenthash].bundle.js`,
crossOriginLoading: false
}
}
const outputValue = generateOutputParams();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question