vue.config.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. const { defineConfig } = require('@vue/cli-service')
  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. const webpack = require("webpack");
  10. module.exports = defineConfig({
  11. // If you want to transpile all dependencies:
  12. transpileDependencies: true,
  13. // If you selectively transpile dependencies:
  14. transpileDependencies: ["@kitware/vtk.js"],
  15. lintOnSave: false, //关闭语法检查
  16. publicPath: '',
  17. outputDir: 'dist',//输出目录
  18. assetsDir: 'static',//编译文件存放目录
  19. // lintOnSave: process.env.NODE_ENV === 'development',//dev环境保存时eslint校验
  20. productionSourceMap: false,//prod环境不启用sourceMap
  21. // hot:"only",
  22. devServer: {
  23. port: port,
  24. allowedHosts: 'all',
  25. historyApiFallback: true,
  26. proxy: {
  27. '/api': {
  28. // target: 'http://localhost:8081/', // 后端接口地址
  29. target: 'http://192.168.131:8187/TransServlet',
  30. //target: 'http://192.168.0.131:8087/TransServlet',
  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:2201/',
  42. secure: false, //接受使用https
  43. changeOrigin: true, //允许跨域
  44. ws: false, //使用websocket
  45. pathRewrite: { // 路径重写
  46. '^/file': ''
  47. }
  48. }, '/websokct':{
  49. target: 'http://192.168.0.131:8081/',
  50. // target: 'http://192.168.0.43:8081/',
  51. // target: 'https://www.gzchain.org.cn/managersvc/', //后端接口地址
  52. secure: false, //接受使用https
  53. }
  54. },
  55. open: false,//不自动打开浏览器
  56. // overlay: {
  57. // warnings: false,
  58. // errors: true
  59. // },
  60. },
  61. configureWebpack: {
  62. // 创建别名(在webpack的name字段中提供别名,以便在index.html中插入正确的引用路径)
  63. name: name,
  64. resolve: {
  65. alias: {
  66. '@': resolve('src')
  67. }
  68. }
  69. },
  70. chainWebpack(config) {
  71. config.plugins.delete('preload') // TODO: need test
  72. config.plugins.delete('prefetch') // TODO: need test
  73. // 设置 svg-sprite-loader 插件生效文件夹(src/icons)
  74. config.module
  75. .rule('svg')
  76. .exclude.add(resolve('src/icons'))
  77. .end()
  78. config.module
  79. .rule('icons')
  80. .test(/\.svg$/)
  81. .include.add(resolve('src/icons'))
  82. .end()
  83. .use('svg-sprite-loader')
  84. .loader('svg-sprite-loader')
  85. .options({
  86. symbolId: 'icon-[name]'
  87. })
  88. .end()
  89. // 设置 preserveWhitespace
  90. config.module
  91. .rule('vue')
  92. .use('vue-loader')
  93. .loader('vue-loader')
  94. .tap(options => {
  95. // options.compilerOptions.preserveWhitespace = true
  96. return options
  97. })
  98. .end()
  99. // config.module
  100. // .rule('THREE')
  101. // .use('imports-loader?THREE=three')
  102. // .loader('imports-loader')
  103. // .end()
  104. // config.module
  105. // .rule('OrbitControls”')
  106. // .use('exports-loader?THREE.OrbitControls')
  107. // .loader('exports-loader')
  108. // .end()
  109. // webpack的SourceMaps 7种打包编译模式详见 https://webpack.js.org/configuration/devtool/#development
  110. config
  111. .when(process.env.NODE_ENV === 'development',
  112. config => config.devtool('cheap-source-map') // 生成一个没有列信息(column-mappings)的SourceMaps文件,不包含loader的sourcemap(譬如babel的sourcemap)
  113. )
  114. config
  115. .when(process.env.NODE_ENV !== 'development',
  116. config => {
  117. config
  118. .plugin('ScriptExtHtmlWebpackPlugin')
  119. .after('html')
  120. .use('script-ext-html-webpack-plugin', [{
  121. // `runtime` 必须与runtimeChunk名称相同,默认值为`runtime`
  122. inline: /runtime\..*\.js$/
  123. }])
  124. .end()
  125. config
  126. .optimization.splitChunks({
  127. chunks: 'all',
  128. cacheGroups: {
  129. libs: {
  130. name: 'chunk-libs',
  131. test: /[\\/]node_modules[\\/]/,
  132. priority: 10,
  133. chunks: 'initial' // 仅打包最初的第三方依赖
  134. },
  135. elementUI: {
  136. name: 'chunk-elementUI', // 将elementUI拆分为一个包
  137. priority: 20, // weight必须大于libs和app,否则将打包成libs或app
  138. test: /[\\/]node_modules[\\/]_?element-plus(.*)/ // 为了适应cnpm
  139. },
  140. commons: {
  141. name: 'chunk-commons',
  142. test: resolve('src/components'), // 可以自定义规则
  143. minChunks: 3, // 最小公共数
  144. priority: 5,
  145. reuseExistingChunk: true
  146. }
  147. }
  148. })
  149. config.optimization.runtimeChunk('single')
  150. }
  151. )
  152. }
  153. })