vue.config.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. const { resolve } = require('path')
  2. const path = require('path')
  3. const WebpackBar = require('webpackbar')
  4. // const dayjs = require('dayjs')
  5. // const time = dayjs().format('YYYY-M-D HH:mm:ss')
  6. const merge = require('webpack-merge')
  7. const tsImportPluginFactory = require('ts-import-plugin')
  8. const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
  9. const productionGzipExtensions = ['js', 'css', 'svg']
  10. // process.env.VUE_APP_UPDATE_TIME = time
  11. const isProduction = process.env.NODE_ENV === 'production'
  12. const cdn = {
  13. css: ['https://cdn.jsdelivr.net/npm/vant@3/lib/index.css'],
  14. js: ['https://unpkg.com/vue@3.2.31/dist/vue.global.js',
  15. 'https://unpkg.com/vue-router@4.0.14/dist/vue-router.global.js',
  16. 'https://unpkg.com/vuex@4.0.2/dist/vuex.global.js',
  17. 'https://cdn.jsdelivr.net/npm/vant@3/lib/vant.min.js',
  18. 'https://cdn.jsdelivr.net/npm/echarts@5.3.2/dist/echarts.min.js'
  19. ]
  20. }
  21. const {
  22. publicPath,
  23. assetsDir,
  24. parallel,
  25. outputDir,
  26. lintOnSave,
  27. transpileDependencies,
  28. title,
  29. devPort,
  30. } = require('./src/config/default/vue.custom.config')
  31. const CompressionPlugin = require('compression-webpack-plugin')
  32. module.exports = {
  33. publicPath,
  34. assetsDir,
  35. parallel,
  36. outputDir,
  37. lintOnSave,
  38. transpileDependencies,
  39. // css: {
  40. // loaderOptions: {
  41. // postcss: {
  42. // plugins: [
  43. // require('postcss-px2rem-exclude')({
  44. // 'remUnit':37.5, //设计稿是750,那么这里的设置就是填750/10=75
  45. // 'propList': ['*', '!border'],
  46. // 'exclude': /node_modules|folder_name/i // 解决UI库px转rem问题 配置忽略node包
  47. // })
  48. // ]
  49. // }
  50. // },
  51. // },
  52. devServer: {
  53. hot: true,
  54. port: devPort,
  55. open: true,
  56. noInfo: false,
  57. overlay: {
  58. warnings: true,
  59. errors: true,
  60. },
  61. proxy: {
  62. '/borui/duoduo-service/': {
  63. target: 'https://duoduoenv.sagacloud.cn',
  64. // target: 'http://192.168.0.47:52015',
  65. changeOrigin: true,
  66. pathRewrite: {
  67. '^/borui/duoduo-service': '/duoduo-service'
  68. }
  69. },
  70. '/borui/server/': {
  71. // target: 'https://duoduoenv.sagacloud.cn',
  72. target: 'http://sso.sagacloud.cn',
  73. changeOrigin: true,
  74. pathRewrite: {
  75. '^/borui/server': '/server'
  76. }
  77. },
  78. '/borui/server1/': {
  79. // target: 'https://duoduoenv.sagacloud.cn',
  80. target: 'http://mng.sagacloud.cn',
  81. changeOrigin: true,
  82. pathRewrite: {
  83. '^/borui/server1': '/server'
  84. }
  85. },
  86. // '/api': {
  87. // target: 'http://api.sagacloud.cn',
  88. // changeOrigin: true,
  89. // pathRewrite: {
  90. // '^/api': ''
  91. // }
  92. // },
  93. // '/duoduo-service/': {
  94. // target: 'https://duoduoenv.sagacloud.cn',
  95. // changeOrigin: true,
  96. // pathRewrite: {
  97. // '^/duoduo-service': '/duoduo-service'
  98. // }
  99. // },
  100. // '/server/': {
  101. // target: 'https://duoduoenv.sagacloud.cn',
  102. // changeOrigin: true,
  103. // pathRewrite: {
  104. // '^/server': '/server'
  105. // }
  106. // },
  107. // '/object/': {
  108. // target: 'http://192.168.0.14:52010',
  109. // changeOrigin: true,
  110. // pathRewrite: {
  111. // '^/object': '/object'
  112. // }
  113. // },
  114. // '/mapServer/': {
  115. // target: 'http://192.168.0.14:52015',
  116. // changeOrigin: true,
  117. // pathRewrite: {
  118. // '^/mapServer': ''
  119. // }
  120. // }
  121. }
  122. },
  123. pluginOptions: {
  124. 'style-resources-loader': {
  125. preProcessor: 'scss',
  126. patterns: [
  127. path.resolve(__dirname, 'src/styles/_variables.scss'),
  128. path.resolve(__dirname, 'src/styles/_mixins.scss'),
  129. ]
  130. }
  131. },
  132. configureWebpack() {
  133. return {
  134. resolve: {
  135. alias: {
  136. '@': resolve('src'),
  137. '*': resolve(''),
  138. 'Assets': resolve('src/assets')
  139. }
  140. },
  141. module: {
  142. rules: [
  143. {
  144. test: /\.(json5?|ya?ml)$/, // target json, json5, yaml and yml files
  145. loader: '@intlify/vue-i18n-loader',
  146. include: [ // Use `Rule.include` to specify the files of locale messages to be pre-compiled
  147. path.resolve(__dirname, 'src/lang')
  148. ]
  149. },
  150. ],
  151. },
  152. plugins: isProduction ? [
  153. // new UglifyJsPlugin({
  154. // uglifyOptions: {
  155. // compress: {
  156. // drop_debugger: true,
  157. // drop_console: true, //生产环境自动删除console
  158. // },
  159. // warnings: false,
  160. // },
  161. // sourceMap: false,
  162. // parallel: true //使用多进程并行运行来提高构建速度。默认并发运行数:os.cpus().length - 1。
  163. // }),
  164. // 配置压缩
  165. new CompressionPlugin({
  166. // test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
  167. threshold: 1024 * 10, // 30K
  168. minRatio: 0.8,
  169. algorithm: 'gzip', // 使用gzip压缩
  170. test: /\.js$|\.css$/, // 匹配文件名
  171. filename: '[path].gz[query]', // 压缩后的文件名(保持原文件名,后缀加.gz)
  172. deleteOriginalAssets: false
  173. }),
  174. new WebpackBar({
  175. name: title
  176. })
  177. ] : [new WebpackBar({
  178. name: title
  179. })],
  180. // externals: isProduction ? {
  181. // 'vue': 'Vue',
  182. // 'vuex': 'Vuex',
  183. // 'vant' : 'vant',
  184. // 'vue-router': 'VueRouter',
  185. // 'echarts': 'echarts'
  186. // } : {}
  187. }
  188. },
  189. chainWebpack: config => {
  190. config.optimization.minimizer('terser').tap((args) => {
  191. args[0].parallel = 4
  192. args[0].terserOptions.compress.warnings = true
  193. args[0].terserOptions.compress.drop_debugger = true
  194. args[0].terserOptions.compress.drop_console = true
  195. return args
  196. })
  197. config.module
  198. .rule('ts')
  199. .use('ts-loader')
  200. .tap(options => {
  201. options = merge(options, {
  202. transpileOnly: true,
  203. getCustomTransformers: () => ({
  204. before: [
  205. tsImportPluginFactory({
  206. libraryName: 'vant',
  207. libraryDirectory: 'es',
  208. style: true
  209. })
  210. ]
  211. }),
  212. compilerOptions: {
  213. module: 'es2015'
  214. }
  215. })
  216. return options
  217. })
  218. }
  219. }