vue.config.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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'])
  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: "8002", //端口号
  74. open: false, //配置自动启动浏览器
  75. hot: true,
  76. proxy: { // 配置跨域处理 可以设置多个
  77. '/simulation/oauth': {
  78. // target: 'http://60.205.245.110:7001', // online-new
  79. target: 'http://192.168.11.221:7001', // 国汽机房
  80. changeOrigin: true,
  81. secure: false, // 如果是https接口,需要配置这个参数
  82. pathRewrite: {
  83. '^/simulation/oauth': '/simulation/oauth'
  84. }
  85. },
  86. '/simulation/resource/common': {
  87. // target: 'http://60.205.245.110:8001', // online-new
  88. target: 'http://192.168.11.221:8001', // 国汽机房
  89. changeOrigin: true,
  90. secure: false, // 如果是https接口,需要配置这个参数
  91. pathRewrite: {
  92. '^/simulation/resource/common': '/simulation/resource/common'
  93. }
  94. },
  95. '/simulation/resource/server': {
  96. // target: 'http://60.205.245.110:8005', // online-new
  97. target: 'http://192.168.11.221:8005', // 国汽机房
  98. changeOrigin: true,
  99. secure: false, // 如果是https接口,需要配置这个参数
  100. pathRewrite: {
  101. '^/simulation/resource/server': '/simulation/resource/server'
  102. }
  103. },
  104. '/simulation/resource/video': {
  105. // target: 'http://60.205.245.110:8007', // online-new
  106. target: 'http://192.168.11.221:8007', // 国汽机房
  107. changeOrigin: true,
  108. secure: false, // 如果是https接口,需要配置这个参数
  109. pathRewrite: {
  110. '^/simulation/resource/server': '/simulation/resource/server'
  111. }
  112. },
  113. }
  114. },
  115. configureWebpack: config => {
  116. const plugins = [];
  117. plugins.push(
  118. new webpack.ProvidePlugin({
  119. $: "jquery",
  120. jQuery: "jquery",
  121. "windows.jQuery": "jquery",
  122. 'window.Quill': 'quill/dist/quill.js',
  123. 'Quill': 'quill/dist/quill.js'
  124. })
  125. )
  126. if (IS_PROD) {
  127. //开启 gzip 压缩
  128. plugins.push(
  129. new CompressionWebpackPlugin({
  130. filename: '[path].gz[query]',
  131. algorithm: 'gzip',
  132. test: productionGzipExtensions,
  133. threshold: 10240,
  134. minRatio: 0.8
  135. })
  136. );
  137. }
  138. config.plugins = [
  139. ...config.plugins,
  140. ...plugins
  141. ];
  142. },
  143. }