web-xiangsonghua/dwt-ems/webpack-ems/releaseHandlePlugin.js

55 lines
2.5 KiB
JavaScript
Raw Permalink Normal View History

2024-12-23 15:13:57 +08:00
function ReleaseHandlePlugin(options) {
this.env = options.env;
}
ReleaseHandlePlugin.prototype.apply = function (complier) {
complier.plugin('compilation', compilation => {
compilation.plugin('optimize-modules', modules => {
modules.forEach(mod => {
try {
if (this.env === 'test') {
// mod._source._value = mod._source._value.replace(/api.dianwutong.com/g, 'api.test.dianwutong.com');
mod._source._value = mod._source._value.replace(/account.dianwutong.com(:\d+)?/g, 'account.dianwutong.com');
mod._source._value = mod._source._value.replace(/ems.dianwutong.com(:\d+)?/g, 'ems.dianwutong.com');
mod._source._value = mod._source._value.replace(/edp.dianwutong.com(:\d+)?/g, 'edp.dianwutong.com');
} else if (this.env === 'production') {
mod._source._value = mod._source._value.replace(/api.dianwutong.com/g, 'api.saas.dianwutong.com');
mod._source._value = mod._source._value.replace(/account.dianwutong.com(:\d+)?/g, 'account.saas.dianwutong.com');
mod._source._value = mod._source._value.replace(/ems.dianwutong.com(:\d+)?/g, 'ems.saas.dianwutong.com');
mod._source._value = mod._source._value.replace(/console.dianwutong.com(:\d+)?/g, 'console.saas.dianwutong.com');
mod._source._value = mod._source._value.replace(/edp.dianwutong.com(:\d+)?/g, 'edp.saas.dianwutong.com');
}
console.log("替换成功")
} catch (error) {
console.error("替换失败")
}
});
});
compilation.plugin(
'html-webpack-plugin-before-html-processing',
(data, cb) => {
let html = data.html;
html = html.replace('<script type="text/javascript" src="build/dev/vendor.dll.js"></script>','');
if(this.env === 'test'){
html = html.replace(/account.dianwutong.com(:\d+)?/g, 'account.test.dianwutong.com')
}else if(this.env === 'production'){
html = html.replace(/account.dianwutong.com(:\d+)?/g, 'account.saas.dianwutong.com')
}
data.html = html;
cb(null, data)
}
)
});
}
module.exports = ReleaseHandlePlugin;