vue.config.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 || 8080 // 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://26t13m1315.wicp.vip:32471/cae/service/TransServlet/',//黄工接口调用地址
  27. // target: 'http://192.168.0.42:8081/', // 亮哥
  28. // target: 'http://192.168.0.15:8081/', // 喻泽
  29. target: 'http://26t13m1315.wicp.vip:32470/', // 测试服
  30. //target: 'http://192.168.0.140:32470/', // 测试服
  31. // target: ' https://www.xigital.com.cn/cae/service/', // 测试服
  32. secure: false, //接受使用https
  33. changeOrigin: true, //允许跨域
  34. ws: false, //使用websocket
  35. pathRewrite: { // 路径重写
  36. '^/api': ''
  37. }
  38. },
  39. '/stage-api': {
  40. target: 'http://192.168.0.140:32470/',
  41. changeOrigin: true,
  42. secure: false,
  43. pathRewrite: {
  44. '^/stage-api': '/'
  45. }
  46. }
  47. },
  48. open: false, //不自动打开浏览器
  49. overlay: {
  50. warnings: false,
  51. errors: true
  52. },
  53. // before: require('./mock/mock-server.js')
  54. },
  55. configureWebpack: {
  56. // 创建别名(在webpack的name字段中提供别名,以便在index.html中插入正确的引用路径)
  57. name: name,
  58. resolve: {
  59. alias: {
  60. '@': resolve('src')
  61. }
  62. }
  63. },
  64. chainWebpack(config) {
  65. config.plugins.delete('preload') // TODO: need test
  66. config.plugins.delete('prefetch') // TODO: need test
  67. // 设置 svg-sprite-loader 插件生效文件夹(src/icons)
  68. config.module
  69. .rule('svg')
  70. .exclude.add(resolve('src/icons'))
  71. .end()
  72. config.module
  73. .rule('icons')
  74. .test(/\.svg$/)
  75. .include.add(resolve('src/icons'))
  76. .end()
  77. .use('svg-sprite-loader')
  78. .loader('svg-sprite-loader')
  79. .options({
  80. symbolId: 'icon-[name]'
  81. })
  82. .end()
  83. // 设置 preserveWhitespace
  84. config.module
  85. .rule('vue')
  86. .use('vue-loader')
  87. .loader('vue-loader')
  88. .tap(options => {
  89. options.compilerOptions.preserveWhitespace = true
  90. return options
  91. })
  92. .end()
  93. // config.module
  94. // .rule('THREE')
  95. // .use('imports-loader?THREE=three')
  96. // .loader('imports-loader')
  97. // .end()
  98. // config.module
  99. // .rule('OrbitControls”')
  100. // .use('exports-loader?THREE.OrbitControls')
  101. // .loader('exports-loader')
  102. // .end()
  103. // webpack的SourceMaps 7种打包编译模式详见 https://webpack.js.org/configuration/devtool/#development
  104. config
  105. .when(process.env.NODE_ENV === 'development',
  106. config => config.devtool('cheap-source-map') // 生成一个没有列信息(column-mappings)的SourceMaps文件,不包含loader的sourcemap(譬如babel的sourcemap)
  107. )
  108. config
  109. .when(process.env.NODE_ENV !== 'development',
  110. config => {
  111. config
  112. .plugin('ScriptExtHtmlWebpackPlugin')
  113. .after('html')
  114. .use('script-ext-html-webpack-plugin', [{
  115. // `runtime` 必须与runtimeChunk名称相同,默认值为`runtime`
  116. inline: /runtime\..*\.js$/
  117. }])
  118. .end()
  119. config
  120. .optimization.splitChunks({
  121. chunks: 'all',
  122. cacheGroups: {
  123. libs: {
  124. name: 'chunk-libs',
  125. test: /[\\/]node_modules[\\/]/,
  126. priority: 10,
  127. chunks: 'initial' // 仅打包最初的第三方依赖
  128. },
  129. elementUI: {
  130. name: 'chunk-elementUI', // 将elementUI拆分为一个包
  131. priority: 20, // weight必须大于libs和app,否则将打包成libs或app
  132. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // 为了适应cnpm
  133. },
  134. commons: {
  135. name: 'chunk-commons',
  136. test: resolve('src/components'), // 可以自定义规则
  137. minChunks: 3, // 最小公共数
  138. priority: 5,
  139. reuseExistingChunk: true
  140. }
  141. }
  142. })
  143. config.optimization.runtimeChunk('single')
  144. }
  145. )
  146. }
  147. }