vue.config.js 5.3 KB

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