vue.config_20240617110608.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. 'use strict'
  2. const path = require('path')
  3. const webpack = require('webpack');
  4. function resolve(dir) {
  5. return path.join(__dirname, dir)
  6. }
  7. const cesiumSource = 'node_modules/cesium/Source';
  8. const cesiumWorkers = '../Build/Cesium/Workers';
  9. const CopyWebpackPlugin = require('copy-webpack-plugin');
  10. const CompressionPlugin = require('compression-webpack-plugin')
  11. const name = process.env.VUE_APP_TITLE || '汽开区城市运行一网统管平台' // 网页标题
  12. const port = process.env.port || process.env.npm_config_port || 11001 // 端口
  13. const { defineConfig } = require('@vue/cli-service')
  14. // vue.config.js 配置说明
  15. //官方vue.config.js 参考文档 https://cli.vuejs.org/zh/config/#css-loaderoptions
  16. // 这里只列一部分,具体配置参考文档
  17. // module.exports = {
  18. // // 部署生产环境和开发环境下的URL。
  19. // // 默认情况下,Vue CLI 会假设你的应用是被部署在一个域名的根路径上
  20. // // 例如 https://www.ruoyi.vip/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.ruoyi.vip/admin/,则设置 baseUrl 为 /admin/。
  21. // publicPath: process.env.NODE_ENV === "production" ? "/" : "/",
  22. // // 在npm run build 或 yarn build 时 ,生成文件的目录名称(要和baseUrl的生产环境路径一致)(默认dist)
  23. // outputDir: 'dist',
  24. // // 用于放置生成的静态资源 (js、css、img、fonts) 的;(项目打包之后,静态资源会放在这个文件夹下)
  25. // assetsDir: 'static',
  26. // // 是否开启eslint保存检测,有效值:ture | false | 'error'
  27. // lintOnSave: process.env.NODE_ENV === 'development',
  28. // // 如果你不需要生产环境的 source map,可以将其设置为 false 以加速生产环境构建。
  29. // productionSourceMap: false,
  30. // // webpack-dev-server 相关配置
  31. // devServer: {
  32. // host: '0.0.0.0',
  33. // port: port,
  34. // open: true,
  35. // proxy: {
  36. // // detail: https://cli.vuejs.org/config/#devserver-proxy
  37. // [process.env.VUE_APP_BASE_API]: {
  38. // target: `http://192.168.4.27:3042`,
  39. // // target: `http://192.168.4.9:8080`,
  40. // changeOrigin: true,
  41. // pathRewrite: {
  42. // ['^' + process.env.VUE_APP_BASE_API]: ''
  43. // }
  44. // }
  45. // },
  46. // disableHostCheck: true
  47. // },
  48. // css: {
  49. // loaderOptions: {
  50. // sass: {
  51. // sassOptions: {outputStyle: "expanded"}
  52. // }
  53. // }
  54. // },
  55. // configureWebpack: {
  56. // name: name,
  57. // devtool: 'source-map',
  58. // output: {
  59. // sourcePrefix: ''
  60. // },
  61. // // resolve: {
  62. // // alias: {
  63. // // '@': resolve('src'),
  64. // // fallback: { "https": false, "zlib": false, "http": false, "url": false },
  65. // // mainFiles: ['index', 'Cesium']
  66. // // },
  67. // // // fallback: { "https": false, "zlib": false, "http": false, "url": false },
  68. // // // mainFiles: ['index', 'Cesium']
  69. // // },
  70. // resolve: {
  71. // fallback: { "https": false, "zlib": false, "http": false, "url": false },
  72. // mainFiles: ['index', 'Cesium']
  73. // },
  74. // plugins: [
  75. // // http://doc.ruoyi.vip/ruoyi-vue/other/faq.html#使用gzip解压缩静态文件
  76. // new CompressionPlugin({
  77. // cache: false, // 不启用文件缓存
  78. // test: /\.(js|css|html|jpe?g|png|gif|svg)?$/i, // 压缩文件格式
  79. // filename: '[path][base].gz[query]', // 压缩后的文件名
  80. // algorithm: 'gzip', // 使用gzip压缩
  81. // minRatio: 0.8, // 压缩比例,小于 80% 的文件不会被压缩
  82. // deleteOriginalAssets: false // 压缩后删除原文件
  83. // }),
  84. // new CopyWebpackPlugin([
  85. // { from: path.join(cesiumSource, cesiumWorkers), to: 'Workers' },
  86. // { from: path.join(cesiumSource, 'Assets'), to: 'Assets' },
  87. // { from: path.join(cesiumSource, 'Widgets'), to: 'Widgets' },
  88. // { from: path.join(cesiumSource, 'ThirdParty'), to: 'ThirdParty' }
  89. // ]),
  90. // new webpack.DefinePlugin({
  91. // // Define relative base path in cesium for loading assets
  92. // CESIUM_BASE_URL: JSON.stringify('')
  93. // })
  94. // ],
  95. // },
  96. // chainWebpack(config) {
  97. // config.plugins.delete('preload') // TODO: need test
  98. // config.plugins.delete('prefetch') // TODO: need test
  99. // // set svg-sprite-loader
  100. // config.module
  101. // .rule('svg')
  102. // .exclude.add(resolve('src/assets/icons'))
  103. // .end()
  104. // config.module
  105. // .rule('icons')
  106. // .test(/\.svg$/)
  107. // .include.add(resolve('src/assets/icons'))
  108. // .end()
  109. // .use('svg-sprite-loader')
  110. // .loader('svg-sprite-loader')
  111. // .options({
  112. // symbolId: 'icon-[name]'
  113. // })
  114. // .end()
  115. // config.when(process.env.NODE_ENV !== 'development', config => {
  116. // config
  117. // .plugin('ScriptExtHtmlWebpackPlugin')
  118. // .after('html')
  119. // .use('script-ext-html-webpack-plugin', [{
  120. // // `runtime` must same as runtimeChunk name. default is `runtime`
  121. // inline: /runtime\..*\.js$/
  122. // }])
  123. // .end()
  124. // config.optimization.splitChunks({
  125. // chunks: 'all',
  126. // cacheGroups: {
  127. // libs: {
  128. // name: 'chunk-libs',
  129. // test: /[\\/]node_modules[\\/]/,
  130. // priority: 10,
  131. // chunks: 'initial' // only package third parties that are initially dependent
  132. // },
  133. // elementUI: {
  134. // name: 'chunk-elementUI', // split elementUI into a single package
  135. // test: /[\\/]node_modules[\\/]_?element-ui(.*)/, // in order to adapt to cnpm
  136. // priority: 20 // the weight needs to be larger than libs and app or it will be packaged into libs or app
  137. // },
  138. // commons: {
  139. // name: 'chunk-commons',
  140. // test: resolve('src/components'), // can customize your rules
  141. // minChunks: 3, // minimum common number
  142. // priority: 5,
  143. // reuseExistingChunk: true
  144. // }
  145. // }
  146. // })
  147. // config.optimization.runtimeChunk('single')
  148. // })
  149. // }
  150. // }
  151. module.exports = defineConfig({
  152. transpileDependencies: true,
  153. productionSourceMap: false,
  154. publicPath: process.env.NODE_ENV === "production" ? "/" : "/",
  155. // 在npm run build 或 yarn build 时 ,生成文件的目录名称(要和baseUrl的生产环境路径一致)(默认dist)
  156. outputDir: 'dist',
  157. // 用于放置生成的静态资源 (js、css、img、fonts) 的;(项目打包之后,静态资源会放在这个文件夹下)
  158. assetsDir: 'static',
  159. // 是否开启eslint保存检测,有效值:ture | false | 'error'
  160. lintOnSave: process.env.NODE_ENV === 'development',
  161. // 如果你不需要生产环境的 source map,可以将其设置为 false 以加速生产环境构建。
  162. productionSourceMap: false,
  163. devServer: {
  164. host: '0.0.0.0',
  165. port: port,
  166. open: true,
  167. proxy: {
  168. // detail: https://cli.vuejs.org/config/#devserver-proxy
  169. [process.env.VUE_APP_BASE_API]: {
  170. target: `http://192.168.4.27:3042`,
  171. // target: `http://192.168.4.9:8080`,
  172. changeOrigin: true,
  173. pathRewrite: {
  174. ['^' + process.env.VUE_APP_BASE_API]: ''
  175. }
  176. }
  177. },
  178. disableHostCheck: true
  179. },
  180. css: {
  181. loaderOptions: {
  182. sass: {
  183. sassOptions: {outputStyle: "expanded"}
  184. }
  185. }
  186. },
  187. configureWebpack: {
  188. devtool: 'source-map',
  189. output: {
  190. sourcePrefix: ''
  191. },
  192. resolve: {
  193. fallback: { "https": false, "zlib": false, "http": false, "url": false },
  194. mainFiles: ['index', 'Cesium']
  195. },
  196. plugins: [
  197. // Copy Cesium Assets, Widgets, and Workers to a static directory
  198. new CopyWebpackPlugin([
  199. { from: path.join(cesiumSource, cesiumWorkers), to: 'Workers' },
  200. { from: path.join(cesiumSource, 'Assets'), to: 'Assets' },
  201. { from: path.join(cesiumSource, 'Widgets'), to: 'Widgets' },
  202. { from: path.join(cesiumSource, 'ThirdParty'), to: 'ThirdParty' }
  203. ]),
  204. new webpack.DefinePlugin({
  205. // Define relative base path in cesium for loading assets
  206. CESIUM_BASE_URL: JSON.stringify('')
  207. })
  208. ],
  209. },
  210. chainWebpack(config) {
  211. config.plugins.delete('preload') // TODO: need test
  212. config.plugins.delete('prefetch') // TODO: need test
  213. // set svg-sprite-loader
  214. config.module
  215. .rule('svg')
  216. .exclude.add(resolve('src/assets/icons'))
  217. .end()
  218. config.module
  219. .rule('icons')
  220. .test(/\.svg$/)
  221. .include.add(resolve('src/assets/icons'))
  222. .end()
  223. .use('svg-sprite-loader')
  224. .loader('svg-sprite-loader')
  225. .options({
  226. symbolId: 'icon-[name]'
  227. })
  228. .end()
  229. config.when(process.env.NODE_ENV !== 'development', config => {
  230. config
  231. .plugin('ScriptExtHtmlWebpackPlugin')
  232. .after('html')
  233. .use('script-ext-html-webpack-plugin', [{
  234. // `runtime` must same as runtimeChunk name. default is `runtime`
  235. inline: /runtime\..*\.js$/
  236. }])
  237. .end()
  238. config.optimization.splitChunks({
  239. chunks: 'all',
  240. cacheGroups: {
  241. libs: {
  242. name: 'chunk-libs',
  243. test: /[\\/]node_modules[\\/]/,
  244. priority: 10,
  245. chunks: 'initial' // only package third parties that are initially dependent
  246. },
  247. elementUI: {
  248. name: 'chunk-elementUI', // split elementUI into a single package
  249. test: /[\\/]node_modules[\\/]_?element-ui(.*)/, // in order to adapt to cnpm
  250. priority: 20 // the weight needs to be larger than libs and app or it will be packaged into libs or app
  251. },
  252. commons: {
  253. name: 'chunk-commons',
  254. test: resolve('src/components'), // can customize your rules
  255. minChunks: 3, // minimum common number
  256. priority: 5,
  257. reuseExistingChunk: true
  258. }
  259. }
  260. })
  261. config.optimization.runtimeChunk('single')
  262. })
  263. }
  264. })