1.iview-cli 关于跨域的问题:
使用webpack-devServer启动node 服务器可以通过配置 proxy 对象实现跨域:
webpack.dev.config.js
devServer: {
proxy: {
//匹配发起的请求的 url
'/report/*': {
// 目标服务器地址
target: 'http://dev.api.tongji.so-quick.cn',
//路径重写
// pathRewrite: {'^/index' : '/'},
changeOrigin: true,
secure: false
}
}
},
- npm run build 报错问题:
iview-cli 没有编译ES6语法,所以 压缩的时候会报错,webpack.prod.config.js 如下修改即可:
3.打包后文件不加 hash 值,如下修改 :
filename: '[name].[hash].js',
chunkFilename: '[name].[hash].chunk.js'
去掉 filename 和 chunkFilename 的 " [hash] " 就可以了。
- 自动生成的 html 文件 中 引入 css 和 js 文件时 ,加后缀 hash 值:
webpack配置的 plugins 里面找到 HtmlWebpackPlugin 插件 ,如下配置即可
new HtmlWebpackPlugin({
filename: '../index_prod.html',
template: './src/template/index.ejs',
inject: false,
// html 文件 引入 js 、 css 增加 hash后缀
hash : true
}),