init commit
This commit is contained in:
50
webpack.plugin.js
Normal file
50
webpack.plugin.js
Normal file
@@ -0,0 +1,50 @@
|
||||
const StrWebpackPlugin = require('str-webpack-plugin');
|
||||
const { version } = require('./package.json');
|
||||
|
||||
function formatDate(input, fmt) {
|
||||
let date;
|
||||
if (input instanceof Date) {
|
||||
date = input;
|
||||
} else {
|
||||
date = new Date(input);
|
||||
}
|
||||
var o = {
|
||||
'M+': date.getMonth() + 1,
|
||||
'd+': date.getDate(),
|
||||
'H+': date.getHours(),
|
||||
'm+': date.getMinutes(),
|
||||
's+': date.getSeconds(),
|
||||
'S+': date.getMilliseconds()
|
||||
};
|
||||
if (/(y+)/.test(fmt)) {
|
||||
fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
|
||||
}
|
||||
for (var k in o) {
|
||||
if (new RegExp('(' + k + ')').test(fmt)) {
|
||||
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (('00' + o[k]).substr(String(o[k]).length)));
|
||||
}
|
||||
}
|
||||
return fmt;
|
||||
}
|
||||
|
||||
let libVersion = `${version}.${formatDate(new Date(), "MMdd.HHmm")}`
|
||||
|
||||
class EnvWebPackage extends StrWebpackPlugin {
|
||||
constructor({ entry, output, env }) {
|
||||
super(Object.keys(entry).map((name) => {
|
||||
return {
|
||||
src: output,
|
||||
test: new RegExp(`${name}.js`, 'g'),
|
||||
replace: {
|
||||
form: [/\$\{lib_env\}/g, /\$\{lib_version\}/g],
|
||||
to: [env, libVersion]
|
||||
}
|
||||
}
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
EnvWebPackage
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user