Created
May 23, 2018 03:34
-
-
Save giscafer/72b9c73493daa13fefb5f26243c63f07 to your computer and use it in GitHub Desktop.
generate hash version for building
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
/*-------------------------------------------------------------- | |
* Copyright (c) Nickbing Lao<[email protected]>. All rights reserved. | |
* Licensed under the MIT License. | |
*-------------------------------------------------------------*/ | |
const fs = require("fs"); | |
const path = require("path"); | |
const reg = /(main|styles|scripts|polyfills|inline).[0-9a-z]*.bundle.(css|js)/g; | |
let indexPagePath = path.join(__dirname, './dist/index.html'); | |
// 读取index 内容,动态添加hash传 | |
let indexContentStr = fs.readFileSync(indexPagePath).toString(); | |
console.log(typeof indexContentStr) | |
let dateHash = new Date().getTime(); | |
let newContent = indexContentStr.replace(reg, `$&?v=${dateHash}`); | |
fs.writeFileSync(indexPagePath, newContent); | |
console.log('hash generate success!'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment