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.t.dianwutong.com'); 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'); } 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(/edp.dianwutong.com(:\d+)?/g, 'edp.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('',''); 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;