1、配置打包后的文件路径
进入config>index.js把assetsPublicPath:'/'改成'./';
build: { env: require('./prod.env'), index: path.resolve(__dirname, '../dist/index.html'), assetsRoot: path.resolve(__dirname, '../dist'), assetsSubDirectory: 'static', assetsPublicPath: './', productionSourceMap: false, productionGzip: false, productionGzipExtensions: ['js', 'css'] bundleAnalyzerReport: process.env.npm_config_report }
2、修改端口号8080为9090,防止端口冲突
进入config>index.js把修改port:9090
module.exports = { dev: { assetsSubDirectory: 'static', assetsPublicPath: '/ host: 'localhost', port: 9090,
3、配置proxyTable 解决开发环境中的跨域问题
module.exports = { dev: { proxyTable: { '/dianping': { target: 'http://****', changeOrigin: true, pathRewrite: { '^/dianping': '/dianping' //此字段根据自己项目填写 } } }
4、有些图片引用失败 在build\webpack.prod.conf.js 的限制limit注释掉
{ test: /\.(png|jpe?g|gif|svg)(\?.*)?$/, loader: 'url-loader', options: { // limit: 10000, name: utils.assetsPath('img/[name].[hash:7].[ext]') } },
5、去掉打包后不要的.map文件
在config\index.js 中把productionSourceMap:true改成productionSourceMap:false
build: { env: require('./prod.env'), index: path.resolve(__dirname, '../dist/index.html'), assetsRoot: path.resolve(__dirname, '../dist'), assetsSubDirectory: 'static', assetsPublicPath: './', productionSourceMap: false, productionGzip: false, productionGzipExtensions: ['js', 'css'] bundleAnalyzerReport: process.env.npm_config_report },
6、build打包发布后css里的图片背景找不到文件
build文件里找到 utils.js 文件,修改如下:
if (options.extract) { return ExtractTextPlugin.extract({ use: loaders, publicPath: '../../', //解决 build css bg img 加载路径不对问题 (添加的就是这行) fallback: 'vue-style-loader' }) } else { return ['vue-style-loader'].concat(loaders) } }