vue.config.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. 'use strict'
  2. const webpack = require('webpack');
  3. const path = require('path')
  4. const resolve = dir => path.resolve(__dirname, dir)
  5. const CompressionWebpackPlugin = require('compression-webpack-plugin');
  6. const productionGzipExtensions = /\.(js|css|json|txt|html|ico|svg)(\?.*)?$/i;
  7. const IS_PROD = ['production', 'prod'].includes(process.env.NODE_ENV);
  8. // 打包分析
  9. const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
  10. module.exports = {
  11. transpileDependencies: ['webpack-dev-server/client'],
  12. // 部署应用时的基本 URL
  13. publicPath: '/',
  14. // 输出文件目录
  15. outputDir: 'dist',
  16. // eslint-loader 是否在保存的时候检查
  17. lintOnSave: false,
  18. assetsDir: '', // 相对于outputDir的静态资源(js、css、img、fonts)目录
  19. //是否使用包含运行时编译器的 Vue 构建版本
  20. runtimeCompiler: true,
  21. // 如果你不需要生产环境的 source map,可以将其设置为 false 以加速生产环境构建
  22. productionSourceMap: false,
  23. chainWebpack: config => {
  24. config
  25. .entry('./src/main.js')
  26. .add('babel-polyfill');
  27. config.resolve.symlinks(true); // 修复热更新失效
  28. // 添加别名
  29. config.resolve.alias
  30. .set('@', resolve('src'))
  31. // .set('assets', resolve('src/assets'))
  32. // .set('components', resolve('src/components'));
  33. // 如果使用多页面打包,使用vue inspect --plugins查看html是否在结果数组中
  34. config.plugin('html').tap(args => {
  35. //修复 Lazy loading routes Error
  36. args[0].chunksSortMode = 'none';
  37. return args;
  38. })
  39. //压缩图片
  40. // config.module
  41. // .rule("images")
  42. // .use("image-webpack-loader")
  43. // .loader("image-webpack-loader")
  44. // .options({
  45. // bypassOnDebug: true
  46. // })
  47. // .end()
  48. // 打包分析, 打包之后自动生成一个名叫report.html文件(可忽视) 查看打包数据使用
  49. if (IS_PROD) {
  50. config.plugin("webpack-report").use(BundleAnalyzerPlugin, [{
  51. analyzerMode: "static"
  52. }]);
  53. }
  54. },
  55. css: {
  56. // extract: true, //解决css热更新失败问题
  57. sourceMap: false,
  58. modules: false,
  59. loaderOptions: {
  60. less: {
  61. javascriptEnabled: true,
  62. }
  63. }
  64. },
  65. //需要npm install style-resources-loader ; 然后执行 vue add style-resources-loader 选择预编译less
  66. pluginOptions: {
  67. 'style-resources-loader': {
  68. preProcessor: 'less',
  69. patterns: ['src/assets/common/css/theme.less']
  70. }
  71. },
  72. devServer: { //跨域
  73. port: "8082", //端口号
  74. open: true, //配置自动启动浏览器
  75. hot: true,
  76. proxy: { // 配置跨域处理 可以设置多个
  77. '/simulation/oauth': {
  78. // target: 'http://10.12.10.70', // windowstest
  79. target: 'http://47.94.105.148:81', // aliyun-new-dev
  80. // target: 'http://47.94.105.148:80', // aliyun-new
  81. changeOrigin: true,
  82. secure: false, // 如果是https接口,需要配置这个参数
  83. pathRewrite: {
  84. '^/simulation/oauth': '/simulation/oauth'
  85. }
  86. },
  87. '/simulation/resource/common': {
  88. // target: 'http://10.10.83.145:6888/user-center',
  89. // target: 'http://10.12.10.70/simulation',
  90. // target: 'http://10.12.10.70:7001', // 登录
  91. // target: 'http://10.12.10.73:7003', // 王志强
  92. // target: 'http://10.12.10.70', // windowstest
  93. // target: 'http://10.12.10.87:8001', // 赵艳
  94. // target: 'http://10.12.10.72:8001', // 王晓峰
  95. // target: 'http://192.168.30.75', // gq
  96. // target: 'http://47.94.105.148', // aliyun
  97. target: 'http://47.94.105.148:81', // aliyun-new-dev
  98. // target: 'http://47.93.217.159', // aliyun-dev
  99. // target: 'http://47.94.105.148:80', // aliyun-new
  100. // target: 'http://10.12.10.74:8001',
  101. changeOrigin: true,
  102. secure: false, // 如果是https接口,需要配置这个参数
  103. pathRewrite: {
  104. '^/simulation/resource/common': '/simulation/resource/common'
  105. }
  106. },
  107. '/simulation/resource/server': {
  108. // target: 'http://10.12.10.73:7003', // 王志强
  109. // target: 'http://10.12.10.88:7003', // 王耀栋
  110. // target: 'http://10.12.10.72:7003', // 王晓峰
  111. // target: 'http://10.12.10.87:7003', // 赵艳
  112. // target: 'http://10.12.10.70', // windowstest
  113. // target: 'http://192.168.30.75', // gq
  114. // target: 'http://47.94.105.148', // aliyun
  115. target: 'http://47.94.105.148:81', // aliyun-new-dev
  116. // target: 'http://47.93.217.159', // aliyun-dev
  117. // target: 'http://47.94.105.148:80', // aliyun-new
  118. // target: 'http://10.12.10.74:7003',// 孟令鑫
  119. changeOrigin: true,
  120. secure: false, // 如果是https接口,需要配置这个参数
  121. pathRewrite: {
  122. '^/simulation/resource/server': '/simulation/resource/server'
  123. }
  124. },
  125. '/simulation/resource/video': {
  126. // target: 'http://10.12.10.73:7003', // 王志强
  127. // target: 'http://10.12.10.88:7003', // 王耀栋
  128. // target: 'http://10.12.10.72:7003', // 王晓峰
  129. // target: 'http://10.12.10.87:7003', // 赵艳
  130. // target: 'http://10.12.10.70', // windowstest
  131. // target: 'http://192.168.30.75', // gq
  132. // target: 'http://47.94.105.148', // aliyun
  133. target: 'http://47.94.105.148:81', // aliyun-new-dev
  134. // target: 'http://47.94.105.148:80', // aliyun-new
  135. // target: 'http://47.93.217.159', // aliyun-dev
  136. // target: 'http://10.12.10.74:7003',// 孟令鑫
  137. changeOrigin: true,
  138. secure: false, // 如果是https接口,需要配置这个参数
  139. pathRewrite: {
  140. '^/simulation/resource/server': '/simulation/resource/server'
  141. }
  142. },
  143. }
  144. },
  145. configureWebpack: config => {
  146. const plugins = [];
  147. plugins.push(
  148. new webpack.ProvidePlugin({
  149. $: "jquery",
  150. jQuery: "jquery",
  151. "windows.jQuery": "jquery",
  152. 'window.Quill': 'quill/dist/quill.js',
  153. 'Quill': 'quill/dist/quill.js'
  154. })
  155. )
  156. if (IS_PROD) {
  157. //开启 gzip 压缩
  158. plugins.push(
  159. new CompressionWebpackPlugin({
  160. filename: '[path].gz[query]',
  161. algorithm: 'gzip',
  162. test: productionGzipExtensions,
  163. threshold: 10240,
  164. minRatio: 0.8
  165. })
  166. );
  167. }
  168. config.plugins = [
  169. ...config.plugins,
  170. ...plugins
  171. ];
  172. },
  173. }