vue.config.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. 'use strict'
  2. const path = require('path') // Node.js的path模块提供了一些用于处理文件路径的小工具
  3. const settings = require('./src/settings.js')
  4. const name = settings.title // 页面标题
  5. const port = process.env.port || process.env.npm_config_port || 8081 // dev端口号
  6. function resolve(dir) {
  7. return path.join(__dirname, dir) // 连接路径,会正确使用当前系统的路径分隔符,Unix系统是"/",Windows系统是"\"
  8. }
  9. // 所有配置项详情请前往 https://cli.vuejs.org/config 查看
  10. module.exports = {
  11. /**
  12. * 如果计划在子路径下部署站点,则需要设置publicPath
  13. * 例如,如果计划将站点部署到https://foo.github.io/bar/,那么publicPath应该设置为“/bar/”。在多数情况下,请使用“/”!!
  14. * 详情参考: https://cli.vuejs.org/config/#publicpath
  15. */
  16. publicPath: './',
  17. outputDir: 'dist', //输出目录
  18. assetsDir: 'static', //编译文件存放目录
  19. lintOnSave: process.env.NODE_ENV === 'development', //dev环境保存时eslint校验
  20. productionSourceMap: false, //prod环境不启用sourceMap
  21. devServer: {
  22. port: port,
  23. disableHostCheck: true,
  24. proxy: {
  25. '/api': {
  26. target: 'http://192.168.0.43:8181/', // 测试服
  27. // target: 'http://26t13m1315.wicp.vip:32471/cae/service/TransServlet/',//黄工接口调用地址
  28. // target: 'http://192.168.0.42:8081/', // 亮哥
  29. // target: 'http://192.168.0.15:8081/', // 喻泽
  30. // target: 'http://26t13m1315.wicp.vip:32470/', // 测试服
  31. // target: 'http://192.168.0.43:8181/', // 测试服
  32. //target: 'http://192.168.0.140:32470/', // 测试服
  33. // target: ' https://www.xigital.com.cn/cae/service/', // 测试服
  34. secure: false, //接受使用https
  35. changeOrigin: true, //允许跨域
  36. ws: false, //使用websocket
  37. pathRewrite: { // 路径重写
  38. '^/api': ''
  39. }
  40. },
  41. '/stage-api': {
  42. target: 'http://192.168.0.140:32470/',
  43. changeOrigin: true,
  44. secure: false,
  45. pathRewrite: {
  46. '^/stage-api': '/'
  47. }
  48. }
  49. },
  50. open: false, //不自动打开浏览器
  51. overlay: {
  52. warnings: false,
  53. errors: true
  54. },
  55. // before: require('./mock/mock-server.js')
  56. },
  57. configureWebpack: {
  58. // 创建别名(在webpack的name字段中提供别名,以便在index.html中插入正确的引用路径)
  59. name: name,
  60. resolve: {
  61. alias: {
  62. '@': resolve('src')
  63. }
  64. }
  65. },
  66. chainWebpack(config) {
  67. config.plugins.delete('preload') // TODO: need test
  68. config.plugins.delete('prefetch') // TODO: need test
  69. // 设置 svg-sprite-loader 插件生效文件夹(src/icons)
  70. config.module
  71. .rule('svg')
  72. .exclude.add(resolve('src/icons'))
  73. .end()
  74. config.module
  75. .rule('icons')
  76. .test(/\.svg$/)
  77. .include.add(resolve('src/icons'))
  78. .end()
  79. .use('svg-sprite-loader')
  80. .loader('svg-sprite-loader')
  81. .options({
  82. symbolId: 'icon-[name]'
  83. })
  84. .end()
  85. // 设置 preserveWhitespace
  86. config.module
  87. .rule('vue')
  88. .use('vue-loader')
  89. .loader('vue-loader')
  90. .tap(options => {
  91. options.compilerOptions.preserveWhitespace = true
  92. return options
  93. })
  94. .end()
  95. // config.module
  96. // .rule('THREE')
  97. // .use('imports-loader?THREE=three')
  98. // .loader('imports-loader')
  99. // .end()
  100. // config.module
  101. // .rule('OrbitControls”')
  102. // .use('exports-loader?THREE.OrbitControls')
  103. // .loader('exports-loader')
  104. // .end()
  105. // webpack的SourceMaps 7种打包编译模式详见 https://webpack.js.org/configuration/devtool/#development
  106. config
  107. .when(process.env.NODE_ENV === 'development',
  108. config => config.devtool('cheap-source-map') // 生成一个没有列信息(column-mappings)的SourceMaps文件,不包含loader的sourcemap(譬如babel的sourcemap)
  109. )
  110. config
  111. .when(process.env.NODE_ENV !== 'development',
  112. config => {
  113. config
  114. .plugin('ScriptExtHtmlWebpackPlugin')
  115. .after('html')
  116. .use('script-ext-html-webpack-plugin', [{
  117. // `runtime` 必须与runtimeChunk名称相同,默认值为`runtime`
  118. inline: /runtime\..*\.js$/
  119. }])
  120. .end()
  121. config
  122. .optimization.splitChunks({
  123. chunks: 'all',
  124. cacheGroups: {
  125. libs: {
  126. name: 'chunk-libs',
  127. test: /[\\/]node_modules[\\/]/,
  128. priority: 10,
  129. chunks: 'initial' // 仅打包最初的第三方依赖
  130. },
  131. elementUI: {
  132. name: 'chunk-elementUI', // 将elementUI拆分为一个包
  133. priority: 20, // weight必须大于libs和app,否则将打包成libs或app
  134. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // 为了适应cnpm
  135. },
  136. commons: {
  137. name: 'chunk-commons',
  138. test: resolve('src/components'), // 可以自定义规则
  139. minChunks: 3, // 最小公共数
  140. priority: 5,
  141. reuseExistingChunk: true
  142. }
  143. }
  144. })
  145. config.optimization.runtimeChunk('single')
  146. }
  147. )
  148. }
  149. }