+ // This value will be injected by Webpack
+ declare const I18N_HASH: string;
export function createTranslateLoader(http: HttpClient) {
- return new TranslateHttpLoader(http, './assets/i18n/', '.json');
+ return new TranslateHttpLoader(http, './assets/i18n/', '.json?v=' + I18N_HASH);
}
Last active
November 6, 2020 12:54
-
-
Save doup/30b9435f8128b338695fafe885ddf764 to your computer and use it in GitHub Desktop.
`ngx-translate` cache busting
package.json
:
{
"scripts": {
…
- "start": "ng serve",
+ "start": "ng serve --extra-webpack-config webpack.partial.js",
- "build": "ng build",
+ "build": "ng build --extra-webpack-config webpack.partial.js",
…
}
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const crypto = require('crypto'); | |
const fs = require('fs'); | |
const glob = require('glob'); | |
const webpack = require('webpack'); | |
function generateChecksum(str, algorithm, encoding) { | |
return crypto | |
.createHash(algorithm || 'md5') | |
.update(str, 'utf8') | |
.digest(encoding || 'hex'); | |
} | |
const content = glob.sync(`src/assets/i18n/**/*.json`) | |
.map(path => fs.readFileSync(path, { encoding: 'utf-8' })) | |
.reduce((content, file) => content + file, '') | |
module.exports = { | |
plugins: [ | |
new webpack.DefinePlugin({ | |
I18N_HASH: JSON.stringify(generateChecksum(content)) | |
}), | |
], | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment