vue.config.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. '/borui/test/': {
  87. // target: 'https://duoduoenv.sagacloud.cn',
  88. target: 'http://192.168.0.47:52015',
  89. changeOrigin: true,
  90. pathRewrite: {
  91. '^/borui/test': ''
  92. }
  93. },
  94. // '/api': {
  95. // target: 'http://api.sagacloud.cn',
  96. // changeOrigin: true,
  97. // pathRewrite: {
  98. // '^/api': ''
  99. // }
  100. // },
  101. // '/duoduo-service/': {
  102. // target: 'https://duoduoenv.sagacloud.cn',
  103. // changeOrigin: true,
  104. // pathRewrite: {
  105. // '^/duoduo-service': '/duoduo-service'
  106. // }
  107. // },
  108. // '/server/': {
  109. // target: 'https://duoduoenv.sagacloud.cn',
  110. // changeOrigin: true,
  111. // pathRewrite: {
  112. // '^/server': '/server'
  113. // }
  114. // },
  115. // '/object/': {
  116. // target: 'http://192.168.0.14:52010',
  117. // changeOrigin: true,
  118. // pathRewrite: {
  119. // '^/object': '/object'
  120. // }
  121. // },
  122. // '/mapServer/': {
  123. // target: 'http://192.168.0.14:52015',
  124. // changeOrigin: true,
  125. // pathRewrite: {
  126. // '^/mapServer': ''
  127. // }
  128. // }
  129. }
  130. },
  131. pluginOptions: {
  132. 'style-resources-loader': {
  133. preProcessor: 'scss',
  134. patterns: [
  135. path.resolve(__dirname, 'src/styles/_variables.scss'),
  136. path.resolve(__dirname, 'src/styles/_mixins.scss'),
  137. ]
  138. }
  139. },
  140. configureWebpack() {
  141. return {
  142. resolve: {
  143. alias: {
  144. '@': resolve('src'),
  145. '*': resolve(''),
  146. 'Assets': resolve('src/assets')
  147. }
  148. },
  149. module: {
  150. rules: [
  151. {
  152. test: /\.(json5?|ya?ml)$/, // target json, json5, yaml and yml files
  153. loader: '@intlify/vue-i18n-loader',
  154. include: [ // Use `Rule.include` to specify the files of locale messages to be pre-compiled
  155. path.resolve(__dirname, 'src/lang')
  156. ]
  157. },
  158. ],
  159. },
  160. plugins: isProduction ? [
  161. // new UglifyJsPlugin({
  162. // uglifyOptions: {
  163. // compress: {
  164. // drop_debugger: true,
  165. // drop_console: true, //生产环境自动删除console
  166. // },
  167. // warnings: false,
  168. // },
  169. // sourceMap: false,
  170. // parallel: true //使用多进程并行运行来提高构建速度。默认并发运行数:os.cpus().length - 1。
  171. // }),
  172. // 配置压缩
  173. new CompressionPlugin({
  174. // test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
  175. threshold: 1024 * 10, // 30K
  176. minRatio: 0.8,
  177. algorithm: 'gzip', // 使用gzip压缩
  178. test: /\.js$|\.css$/, // 匹配文件名
  179. filename: '[path].gz[query]', // 压缩后的文件名(保持原文件名,后缀加.gz)
  180. deleteOriginalAssets: false
  181. }),
  182. new WebpackBar({
  183. name: title
  184. })
  185. ] : [new WebpackBar({
  186. name: title
  187. })],
  188. // externals: isProduction ? {
  189. // 'vue': 'Vue',
  190. // 'vuex': 'Vuex',
  191. // 'vant' : 'vant',
  192. // 'vue-router': 'VueRouter',
  193. // 'echarts': 'echarts'
  194. // } : {}
  195. }
  196. },
  197. chainWebpack: config => {
  198. config.optimization.minimizer('terser').tap((args) => {
  199. args[0].parallel = 4
  200. args[0].terserOptions.compress.warnings = true
  201. args[0].terserOptions.compress.drop_debugger = true
  202. args[0].terserOptions.compress.drop_console = true
  203. return args
  204. })
  205. config.module
  206. .rule('ts')
  207. .use('ts-loader')
  208. .tap(options => {
  209. options = merge(options, {
  210. transpileOnly: true,
  211. getCustomTransformers: () => ({
  212. before: [
  213. tsImportPluginFactory({
  214. libraryName: 'vant',
  215. libraryDirectory: 'es',
  216. style: true
  217. })
  218. ]
  219. }),
  220. compilerOptions: {
  221. module: 'es2015'
  222. }
  223. })
  224. return options
  225. })
  226. }
  227. }