vue.config_20240617110528.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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. patterns: [
  200. { from: path.join(cesiumSource, cesiumWorkers), to: 'Workers' },
  201. { from: path.join(cesiumSource, 'Assets'), to: 'Assets' },
  202. { from: path.join(cesiumSource, 'Widgets'), to: 'Widgets' },
  203. { from: path.join(cesiumSource, 'ThirdParty'), to: 'ThirdParty' }
  204. ]
  205. }),
  206. new webpack.DefinePlugin({
  207. // Define relative base path in cesium for loading assets
  208. CESIUM_BASE_URL: JSON.stringify('')
  209. })
  210. ],
  211. },
  212. chainWebpack(config) {
  213. config.plugins.delete('preload') // TODO: need test
  214. config.plugins.delete('prefetch') // TODO: need test
  215. // set svg-sprite-loader
  216. config.module
  217. .rule('svg')
  218. .exclude.add(resolve('src/assets/icons'))
  219. .end()
  220. config.module
  221. .rule('icons')
  222. .test(/\.svg$/)
  223. .include.add(resolve('src/assets/icons'))
  224. .end()
  225. .use('svg-sprite-loader')
  226. .loader('svg-sprite-loader')
  227. .options({
  228. symbolId: 'icon-[name]'
  229. })
  230. .end()
  231. config.when(process.env.NODE_ENV !== 'development', config => {
  232. config
  233. .plugin('ScriptExtHtmlWebpackPlugin')
  234. .after('html')
  235. .use('script-ext-html-webpack-plugin', [{
  236. // `runtime` must same as runtimeChunk name. default is `runtime`
  237. inline: /runtime\..*\.js$/
  238. }])
  239. .end()
  240. config.optimization.splitChunks({
  241. chunks: 'all',
  242. cacheGroups: {
  243. libs: {
  244. name: 'chunk-libs',
  245. test: /[\\/]node_modules[\\/]/,
  246. priority: 10,
  247. chunks: 'initial' // only package third parties that are initially dependent
  248. },
  249. elementUI: {
  250. name: 'chunk-elementUI', // split elementUI into a single package
  251. test: /[\\/]node_modules[\\/]_?element-ui(.*)/, // in order to adapt to cnpm
  252. priority: 20 // the weight needs to be larger than libs and app or it will be packaged into libs or app
  253. },
  254. commons: {
  255. name: 'chunk-commons',
  256. test: resolve('src/components'), // can customize your rules
  257. minChunks: 3, // minimum common number
  258. priority: 5,
  259. reuseExistingChunk: true
  260. }
  261. }
  262. })
  263. config.optimization.runtimeChunk('single')
  264. })
  265. }
  266. })