2021-01-12 13:17:26 +08:00
|
|
|
const transformIndexHtml = (code) => {
|
|
|
|
switch (process.env.NODE_ENV) {
|
|
|
|
case 'production':
|
2021-02-17 23:31:56 +08:00
|
|
|
return code.replace(/__INDEX__/, '/demo/index.prod.js')
|
2021-01-12 13:17:26 +08:00
|
|
|
default:
|
2021-02-17 23:31:56 +08:00
|
|
|
return code.replace(/__INDEX__/, '/demo/index.dev.js')
|
2021-01-12 13:17:26 +08:00
|
|
|
}
|
|
|
|
}
|
2021-02-17 23:31:56 +08:00
|
|
|
|
2021-01-12 13:17:26 +08:00
|
|
|
const demoIndexTransFormPlugin = {
|
|
|
|
name: 'demo-transform',
|
|
|
|
enforce: 'pre',
|
|
|
|
// vite build is production will not invoke `transformIndexHtml`
|
|
|
|
transform (code, id) {
|
|
|
|
if (id.endsWith('.html')) {
|
|
|
|
return { code: transformIndexHtml(code), map: null }
|
|
|
|
}
|
|
|
|
},
|
|
|
|
transformIndexHtml
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = demoIndexTransFormPlugin
|