vue.config.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. 'use strict'
  2. const path = require('path')
  3. const defaultSettings = require('./src/settings.js')
  4. const CompressionWebpackPlugin = require('compression-webpack-plugin')
  5. const webpack = require('webpack')
  6. function resolve(dir) {
  7. return path.join(__dirname, dir)
  8. }
  9. const name = defaultSettings.title || '登录系统' // page title
  10. const BASE_URL = process.env.NODE_ENV === 'production' ? 'http://118.24.21.156:8087' : 'http://118.24.21.156:8087'// 这个BASE_URL这里没有用到,在request.js里面重新定义了后端接口
  11. const port = 9527
  12. // const port = process.env.port || process.env.npm_config_port || 9528 // dev por
  13. module.exports = {
  14. /**
  15. * 如果计划在子路径下部署站点,则需要设置publicPath
  16. */
  17. publicPath: '/',
  18. outputDir: 'dist',
  19. assetsDir: 'static',
  20. // lintOnSave: process.env.NODE_ENV === 'development',
  21. lintOnSave: false,
  22. productionSourceMap: false, // 生产环境是否生成 sourceMap 文件
  23. devServer: {
  24. // host: '192.168.31.235',
  25. port: port, // 端口
  26. open: true, // 自动开启浏览器
  27. compress: false, // 开启压缩
  28. overlay: {
  29. warnings: false,
  30. errors: false
  31. },
  32. proxy: {
  33. '/backstage': {
  34. target: 'http://36.138.232.124:10085',
  35. changeOrigin: true,
  36. pathRewrite: {
  37. '^/backstage': ''
  38. }
  39. },
  40. '/api': {
  41. target: 'http://36.138.232.124:10085',
  42. changeOrigin: true,
  43. pathRewrite: {
  44. '^/api': ''
  45. }
  46. },
  47. '/service': {
  48. target: 'http://36.138.232.124:10085',
  49. changeOrigin: true,
  50. pathRewrite: {
  51. '^/service': '/service'
  52. }
  53. },
  54. '/arcgis/rest': {
  55. target: 'http://36.138.232.124:6080',
  56. changeOrigin: true,
  57. pathRewrite: {
  58. '^/arcgis/rest': '/arcgis/rest'
  59. }
  60. },
  61. }
  62. // before: require('./mock/mock-server.js')
  63. },
  64. css: {
  65. // 是否使用css分离插件 ExtractTextPlugin
  66. extract: false,
  67. // 开启 CSS source maps?
  68. sourceMap: true,
  69. // css预设器配置项
  70. loaderOptions: {
  71. // pass options to sass-loader
  72. sass: {
  73. // 引入全局变量样式,@使我们设置的别名,执行src目录
  74. data: `@import "@/styles/index.scss";`
  75. }
  76. },
  77. // 启用 CSS modules for all css / pre-processor files.
  78. modules: false
  79. },
  80. configureWebpack: {
  81. name: name,
  82. resolve: {
  83. alias: {
  84. '@': resolve('src'),
  85. 'staticPub': resolve('public')
  86. }
  87. },
  88. // // devtool: '#eval-source-map',
  89. // plugins: [// 压缩代码
  90. // new CompressionWebpackPlugin(
  91. // {
  92. // filename: '[path].gz[query]',
  93. // algorithm: 'gzip',
  94. // test: /\.js$|\.html$|\.json$|\.css/,
  95. // threshold: 0, // 只有大小大于该值的资源会被处理
  96. // minRatio: 0.8, // 只有压缩率小于这个值的资源才会被处理
  97. // deleteOriginalAssets: false // 删除原文件
  98. // }
  99. // ),
  100. // new webpack.ProvidePlugin(
  101. // {
  102. // $: 'jquery',
  103. // jQuery: 'jquery',
  104. // 'windows.jQuery': 'jquery'
  105. // }
  106. // )
  107. // ]
  108. },
  109. chainWebpack(config) {
  110. // 删除预加载
  111. config.plugins.delete('preload')
  112. config.plugins.delete('prefetch')
  113. // 设置 svg-sprite-loader
  114. config.module
  115. .rule('svg')
  116. .exclude.add(resolve('src/icons'))
  117. .end()
  118. config.module
  119. .rule('icons')
  120. .test(/\.svg$/)
  121. .include.add(resolve('src/icons'))
  122. .end()
  123. .use('svg-sprite-loader')
  124. .loader('svg-sprite-loader')
  125. .options({
  126. symbolId: 'icon-[name]'
  127. })
  128. .end()
  129. // 设置保留空白
  130. config.module
  131. .rule('vue')
  132. .use('vue-loader')
  133. .loader('vue-loader')
  134. .tap(options => {
  135. options.compilerOptions.preserveWhitespace = true
  136. return options
  137. })
  138. .end()
  139. config
  140. .when(process.env.NODE_ENV === 'development',
  141. config => config.devtool('cheap-source-map')
  142. )
  143. config
  144. .when(process.env.NODE_ENV !== 'development',
  145. config => {
  146. config
  147. .plugin('ScriptExtHtmlWebpackPlugin')
  148. .after('html')
  149. .use('script-ext-html-webpack-plugin', [{
  150. // `runtime`必须与runtimeChunk名称相同。默认值为“runtime”`
  151. inline: /runtime\..*\.js$/
  152. }])
  153. .end()
  154. // 分割代码
  155. config
  156. .optimization.splitChunks({
  157. chunks: 'all',
  158. cacheGroups: {
  159. libs: {
  160. name: 'chunk-libs',
  161. test: /[\\/]node_modules[\\/]/,
  162. priority: 10,
  163. chunks: 'initial' // 仅打包最初依赖的第三方
  164. },
  165. elementUI: {
  166. name: 'chunk-elementUI', // 将elementUI拆分为一个包
  167. priority: 20, // 重量必须大于libs和app,否则将打包成libs或app
  168. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // 为了适应cnpm
  169. },
  170. commons: {
  171. name: 'chunk-commons',
  172. test: resolve('src/components'), // 可以自定义规则
  173. minChunks: 3, // 最小公共数
  174. priority: 5,
  175. reuseExistingChunk: true
  176. }
  177. }
  178. })
  179. config.optimization.runtimeChunk('single')
  180. }
  181. )
  182. config.externals({ './cptable': 'var cptable' })
  183. }
  184. }