vue.config.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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 = 10012
  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. '/auth/': {
  62. target: 'http://192.168.2.3:10095',
  63. changeOrigin: true,
  64. pathRewrite: {
  65. '^/auth/': '/auth/'
  66. }
  67. },
  68. '/base': {
  69. target: 'http://192.168.2.3:10095',
  70. changeOrigin: true,
  71. pathRewrite: {
  72. '^/base': '/base'
  73. }
  74. },
  75. '/sxbapi': {
  76. target: 'http://192.168.2.85:10209/api',
  77. changeOrigin: true,
  78. pathRewrite: {
  79. '^/sxbapi': ''
  80. }
  81. },
  82. '/hdcapi': {
  83. target: 'http://192.168.2.229:10209/api',
  84. changeOrigin: true,
  85. pathRewrite: {
  86. '^/hdcapi': ''
  87. }
  88. },
  89. }
  90. // before: require('./mock/mock-server.js')
  91. },
  92. css: {
  93. // 是否使用css分离插件 ExtractTextPlugin
  94. extract: false,
  95. // 开启 CSS source maps?
  96. sourceMap: true,
  97. // css预设器配置项
  98. loaderOptions: {
  99. // pass options to sass-loader
  100. sass: {
  101. // 引入全局变量样式,@使我们设置的别名,执行src目录
  102. data: `@import "@/styles/index.scss";`
  103. }
  104. },
  105. // 启用 CSS modules for all css / pre-processor files.
  106. modules: false
  107. },
  108. configureWebpack: {
  109. name: name,
  110. resolve: {
  111. alias: {
  112. '@': resolve('src'),
  113. 'staticPub': resolve('public')
  114. }
  115. },
  116. // // devtool: '#eval-source-map',
  117. // plugins: [// 压缩代码
  118. // new CompressionWebpackPlugin(
  119. // {
  120. // filename: '[path].gz[query]',
  121. // algorithm: 'gzip',
  122. // test: /\.js$|\.html$|\.json$|\.css/,
  123. // threshold: 0, // 只有大小大于该值的资源会被处理
  124. // minRatio: 0.8, // 只有压缩率小于这个值的资源才会被处理
  125. // deleteOriginalAssets: false // 删除原文件
  126. // }
  127. // ),
  128. // new webpack.ProvidePlugin(
  129. // {
  130. // $: 'jquery',
  131. // jQuery: 'jquery',
  132. // 'windows.jQuery': 'jquery'
  133. // }
  134. // )
  135. // ]
  136. },
  137. chainWebpack(config) {
  138. // 删除预加载
  139. config.plugins.delete('preload')
  140. config.plugins.delete('prefetch')
  141. // 设置 svg-sprite-loader
  142. config.module
  143. .rule('svg')
  144. .exclude.add(resolve('src/icons'))
  145. .end()
  146. config.module
  147. .rule('icons')
  148. .test(/\.svg$/)
  149. .include.add(resolve('src/icons'))
  150. .end()
  151. .use('svg-sprite-loader')
  152. .loader('svg-sprite-loader')
  153. .options({
  154. symbolId: 'icon-[name]'
  155. })
  156. .end()
  157. // 设置保留空白
  158. config.module
  159. .rule('vue')
  160. .use('vue-loader')
  161. .loader('vue-loader')
  162. .tap(options => {
  163. options.compilerOptions.preserveWhitespace = true
  164. return options
  165. })
  166. .end()
  167. config
  168. .when(process.env.NODE_ENV === 'development',
  169. config => config.devtool('cheap-source-map')
  170. )
  171. config
  172. .when(process.env.NODE_ENV !== 'development',
  173. config => {
  174. config
  175. .plugin('ScriptExtHtmlWebpackPlugin')
  176. .after('html')
  177. .use('script-ext-html-webpack-plugin', [{
  178. // `runtime`必须与runtimeChunk名称相同。默认值为“runtime”`
  179. inline: /runtime\..*\.js$/
  180. }])
  181. .end()
  182. // 分割代码
  183. config
  184. .optimization.splitChunks({
  185. chunks: 'all',
  186. cacheGroups: {
  187. libs: {
  188. name: 'chunk-libs',
  189. test: /[\\/]node_modules[\\/]/,
  190. priority: 10,
  191. chunks: 'initial' // 仅打包最初依赖的第三方
  192. },
  193. elementUI: {
  194. name: 'chunk-elementUI', // 将elementUI拆分为一个包
  195. priority: 20, // 重量必须大于libs和app,否则将打包成libs或app
  196. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // 为了适应cnpm
  197. },
  198. commons: {
  199. name: 'chunk-commons',
  200. test: resolve('src/components'), // 可以自定义规则
  201. minChunks: 3, // 最小公共数
  202. priority: 5,
  203. reuseExistingChunk: true
  204. }
  205. }
  206. })
  207. config.optimization.runtimeChunk('single')
  208. }
  209. )
  210. config.externals({ './cptable': 'var cptable' })
  211. }
  212. }