文件
require('./build')
属性上
type: process.env.type
}
3、在package.json文件中添加npm run testing命令
添加testing命令
"build": "node build/build.js"
4、config ->index.js中把build这个命令复制一份改成testing(此步为了打包到不同文件夹)
productionSourceMap: true,// https://webpack.js.org/configuration/devtool/#production
devtool: '#source-map',// Gzip off by default as many popular static hosts such as
// Surge or Netlify already gzip all static assets for you.
// Before setting to
// npm install --save-dev compression-webpack-plugin
productionGzip: false,productionGzipExtensions: ['js','css'],// Run the build command with an extra argument to
// View the bundle analyzer report after build finishes:
//
// Set to
bundleAnalyzerReport: process.env.npm_config_report
},testing: {
env: require('./prod.env'),index: path.resolve(dirname,'../testing/index.html'),assetsRoot: path.resolve(dirname,'../testing'),assetsPublicPath: '/',productionSourceMap: true,
devtool: '#source-map',// Gzip off by default as many popular static hosts such as
// Surge or Netlify already gzip all static assets for you.
// Before setting to
true
,make sure to:// npm install --save-dev compression-webpack-plugin
productionGzip: false,productionGzipExtensions: ['js','css'],// Run the build command with an extra argument to
// View the bundle analyzer report after build finishes:
//
npm run build --report
// Set to
true
or false
to always turn it on or offbundleAnalyzerReport: process.env.npm_config_report
},testing: {
env: require('./prod.env'),index: path.resolve(dirname,'../testing/index.html'),assetsRoot: path.resolve(dirname,'../testing'),assetsPublicPath: '/',productionSourceMap: true,
5、修改build->webpack.prod.conf文件
修改filename
filename: process.env.type == '"testing"' ? config.testing.index : config.build.index
}),
}),
修改output
路径都修改为根据正式、测试环境判断(不然执行npm run testing,npm run build命令时输出的文件有问题)
代码如下:
{
7、根据不同环境配置不同域名地址
最后执行:
npm run testing 就会执行测试环境配置的地址,并生成testing文件夹 npm run build就会执行正式环境配置的地址,并生成dist文件夹
原文链接:https://www.f2er.com/vue/31517.html