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

56 lines
2.6 KiB
JavaScript
Raw 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')
mod._source._value = mod._source._value.replace(/console.dianwutong.com(:\d+)?/g, 'console.dianwutong.com')
} else if (this.env === 'production') {
2024-12-26 17:02:02 +08:00
mod._source._value = mod._source._value.replace(/api.dianwutong.com/g, 'cdyapi.saas.dianwutong.com')
mod._source._value = mod._source._value.replace(/account.dianwutong.com(:\d+)?/g, 'cdyaccount.saas.dianwutong.com')
mod._source._value = mod._source._value.replace(/ems.dianwutong.com(:\d+)?/g, 'cdyems.saas.dianwutong.com')
mod._source._value = mod._source._value.replace(/console.dianwutong.com(:\d+)?/g, 'cdyconsole.saas.dianwutong.com')
mod._source._value = mod._source._value.replace(/edp.dianwutong.com(:\d+)?/g, 'cdyedp.saas.dianwutong.com')
2024-12-23 15:13:57 +08:00
}
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