vue.config.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. const type = {
  14. company: 'company',
  15. client: 'client'
  16. }
  17. //本地环境
  18. // const currentType=type.company;
  19. //客户环境
  20. const currentType=type.client;
  21. module.exports = {
  22. /**
  23. * 如果计划在子路径下部署站点,则需要设置publicPath
  24. */
  25. publicPath: '/',
  26. outputDir: 'dist',
  27. assetsDir: 'static',
  28. // lintOnSave: process.env.NODE_ENV === 'development',
  29. lintOnSave: false,
  30. productionSourceMap: false, // 生产环境是否生成 sourceMap 文件
  31. devServer: {
  32. // host: '192.168.31.235',
  33. port: port, // 端口
  34. open: true, // 自动开启浏览器
  35. compress: false, // 开启压缩
  36. overlay: {
  37. warnings: false,
  38. errors: false
  39. },
  40. proxy:{
  41. // '^/mbData': {
  42. // target: 'http://117.176.120.161:8053',
  43. // changeOrigin: true,
  44. // pathRewrite: {
  45. // '^/mbData': '/'
  46. // }
  47. // },
  48. '^/mbData/api': {
  49. target: 'http://117.176.120.161:1111',
  50. changeOrigin: true,
  51. pathRewrite: {
  52. '^/mbData/api': ''
  53. }
  54. },
  55. '^/mbData/service':{
  56. target: 'http://117.176.120.194:8085',
  57. changeOrigin: true,
  58. pathRewrite: {
  59. '^/mbData/service': '/service'
  60. }
  61. },
  62. '/arcgis/rest': {
  63. target: 'http://36.138.232.112:6080',
  64. changeOrigin: true,
  65. pathRewrite: {
  66. '^/arcgis/rest': '/arcgis/rest'
  67. }
  68. },
  69. // '^/(api||service||login||base||dc||tofly-scada||flow-project||auth||mis||gis||gps||dispatch-manage||water-quality)/':{
  70. // // target: 'http://221.182.8.141:10085',
  71. // // target:"http://221.182.8.141:10077",
  72. // // target:"http://192.168.2.15:10077",
  73. // //公司环境
  74. // // target:"http://221.182.8.141:10077",
  75. // //客户环境
  76. // target:"http://172.16.0.4:10077",
  77. // changeOrigin: true,
  78. // },
  79. '^/(api||service||login||base||dc||tofly-scada||flow-project||auth||mis||gis||gps||dispatch-manage||water-quality||callfile)/':{
  80. // target: 'http://221.182.8.141:10085',
  81. // target:"http://221.182.8.141:10077",
  82. // target:"http://192.168.2.15:10077",
  83. // //公司环境
  84. // target:"http://221.182.8.141:7077",
  85. //客户环境
  86. target:currentType==type.company?"http://221.182.8.141:7077":"http://172.16.0.4:10077",
  87. // target:currentType==type.company?"http://221.182.8.141:7077":"http://172.16.0.2:11020",
  88. changeOrigin: true,
  89. }
  90. },
  91. // {
  92. // context:['/api','/service','/login','/base','/dc','/tofly-scada',
  93. // '/flow-project','/auth','/mis','/gis','/gps','/dispatch-manage',
  94. // '/water-quality'],
  95. // target: 'http://221.182.8.141:10085',
  96. // }]
  97. // before: require('./mock/mock-server.js')
  98. },
  99. css: {
  100. // 是否使用css分离插件 ExtractTextPlugin
  101. extract: false,
  102. // 开启 CSS source maps?
  103. sourceMap: true,
  104. // css预设器配置项
  105. loaderOptions: {
  106. // pass options to sass-loader
  107. sass: {
  108. // 引入全局变量样式,@使我们设置的别名,执行src目录
  109. data: `@import "@/styles/index.scss";`
  110. }
  111. },
  112. // 启用 CSS modules for all css / pre-processor files.
  113. modules: false
  114. },
  115. configureWebpack: {
  116. name: name,
  117. resolve: {
  118. alias: {
  119. '@': resolve('src'),
  120. 'staticPub': resolve('public')
  121. }
  122. },
  123. output:{
  124. filename:'js/[name].[hash:8].js',
  125. chunkFilename:'js/[name].[hash:8].js',
  126. },
  127. // devtool: '#eval-source-map',
  128. plugins: [// 压缩代码
  129. new CompressionWebpackPlugin(
  130. {
  131. filename: '[path].gz[query]',
  132. algorithm: 'gzip',
  133. test: /\.js$|\.html$|\.json$|\.css/,
  134. threshold: 0, // 只有大小大于该值的资源会被处理
  135. minRatio: 0.8, // 只有压缩率小于这个值的资源才会被处理
  136. deleteOriginalAssets: false // 删除原文件
  137. }
  138. ),
  139. new webpack.ProvidePlugin(
  140. {
  141. $: 'jquery',
  142. jQuery: 'jquery',
  143. 'windows.jQuery': 'jquery'
  144. }
  145. )
  146. ]
  147. },
  148. chainWebpack(config) {
  149. // 删除预加载
  150. config.plugins.delete('preload')
  151. config.plugins.delete('prefetch')
  152. // 设置 svg-sprite-loader
  153. config.module
  154. .rule('svg')
  155. .exclude.add(resolve('src/icons'))
  156. .end()
  157. config.module
  158. .rule('icons')
  159. .test(/\.svg$/)
  160. .include.add(resolve('src/icons'))
  161. .end()
  162. .use('svg-sprite-loader')
  163. .loader('svg-sprite-loader')
  164. .options({
  165. symbolId: 'icon-[name]'
  166. })
  167. .end()
  168. // 设置保留空白
  169. config.module
  170. .rule('vue')
  171. .use('vue-loader')
  172. .loader('vue-loader')
  173. .tap(options => {
  174. options.compilerOptions.preserveWhitespace = true
  175. return options
  176. })
  177. .end()
  178. config
  179. .when(process.env.NODE_ENV === 'development',
  180. config => config.devtool('cheap-source-map')
  181. )
  182. config
  183. .when(process.env.NODE_ENV !== 'development',
  184. config => {
  185. config
  186. .plugin('ScriptExtHtmlWebpackPlugin')
  187. .after('html')
  188. .use('script-ext-html-webpack-plugin', [{
  189. // `runtime`必须与runtimeChunk名称相同。默认值为“runtime”`
  190. inline: /runtime\..*\.js$/
  191. }])
  192. .end()
  193. // 分割代码
  194. config
  195. .optimization.splitChunks({
  196. chunks: 'all',
  197. cacheGroups: {
  198. libs: {
  199. name: 'chunk-libs',
  200. test: /[\\/]node_modules[\\/]/,
  201. priority: 10,
  202. chunks: 'initial' // 仅打包最初依赖的第三方
  203. },
  204. elementUI: {
  205. name: 'chunk-elementUI', // 将elementUI拆分为一个包
  206. priority: 20, // 重量必须大于libs和app,否则将打包成libs或app
  207. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // 为了适应cnpm
  208. },
  209. commons: {
  210. name: 'chunk-commons',
  211. test: resolve('src/components'), // 可以自定义规则
  212. minChunks: 3, // 最小公共数
  213. priority: 5,
  214. reuseExistingChunk: true
  215. }
  216. }
  217. })
  218. config.optimization.runtimeChunk('single')
  219. }
  220. )
  221. const oneOfsMap = config.module.rule('scss').oneOfs.store
  222. oneOfsMap.forEach(item => {
  223. item
  224. .use('sass-resources-loader')
  225. .loader('sass-resources-loader')
  226. .options({
  227. resources: './src/styles/global.scss'
  228. })
  229. .end()
  230. })
  231. }
  232. }