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

51 lines
2.2 KiB
JavaScript
Raw Normal View History

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