引言:在項目開發中,遇到了開發環境和生產環境使用模板不同的情況,配置如下:
一、vue.config.js
const path = require('path')
function resolve(dir){return path.join(__dirname,dir)
}
module.exports = {chainWebpack: config => {config.plugin('html').tap(args => {args[0].template = process.env.NODE_ENV === 'development'? resolve('./public/index_dev.html'): resolve('./public/index.html');return args})},
}
二、創建一個index_dev.html
三、package.json 的命令配置
"serve": "vue-cli-service serve --mode development",
這時候就可以根據環境不同實現模板不同