vue.config.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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':98, //设计稿是750,那么这里的设置就是填750/10=75
  45. // 'propList': ['*', '!border','!border-left','!border-right'],
  46. // 'exclude': /node_modules|folder_name/i // 解决UI库px转rem问题 配置忽略node包
  47. // })
  48. // ]
  49. // }
  50. // },
  51. // },
  52. css: {
  53. loaderOptions: {
  54. postcss: {
  55. plugins: [
  56. require('postcss-pxtorem')({ // 把px单位换算成rem单位
  57. rootValue: 98, // vant官方使用的是37.5
  58. minPixelValue:4,
  59. unitPrecision:3,
  60. // selectorBlackList: ['vant', 'mu'], // 忽略转换正则匹配项
  61. propList: ['*']
  62. })
  63. ]
  64. }
  65. }
  66. },
  67. devServer: {
  68. hot: true,
  69. port: devPort,
  70. open: true,
  71. noInfo: false,
  72. overlay: {
  73. warnings: true,
  74. errors: true,
  75. },
  76. proxy: {
  77. '/borui/duoduo-service/': {
  78. target: 'https://duoduoenv.sagacloud.cn',
  79. // target: 'http://192.168.0.47:52015',
  80. changeOrigin: true,
  81. pathRewrite: {
  82. '^/borui/duoduo-service': '/duoduo-service'
  83. }
  84. },
  85. '/borui/server/': {
  86. // target: 'https://duoduoenv.sagacloud.cn',
  87. target: 'http://sso.sagacloud.cn',
  88. changeOrigin: true,
  89. pathRewrite: {
  90. '^/borui/server': '/server'
  91. }
  92. },
  93. '/borui/server1/': {
  94. // target: 'https://duoduoenv.sagacloud.cn',
  95. target: 'http://mng.sagacloud.cn',
  96. changeOrigin: true,
  97. pathRewrite: {
  98. '^/borui/server1': '/server'
  99. }
  100. },
  101. '/borui/test/': {
  102. // target: 'https://duoduoenv.sagacloud.cn',
  103. target: 'http://192.168.0.47:52015',
  104. changeOrigin: true,
  105. pathRewrite: {
  106. '^/borui/test': ''
  107. }
  108. },
  109. // '/api': {
  110. // target: 'http://api.sagacloud.cn',
  111. // changeOrigin: true,
  112. // pathRewrite: {
  113. // '^/api': ''
  114. // }
  115. // },
  116. // '/duoduo-service/': {
  117. // target: 'https://duoduoenv.sagacloud.cn',
  118. // changeOrigin: true,
  119. // pathRewrite: {
  120. // '^/duoduo-service': '/duoduo-service'
  121. // }
  122. // },
  123. // '/server/': {
  124. // target: 'https://duoduoenv.sagacloud.cn',
  125. // changeOrigin: true,
  126. // pathRewrite: {
  127. // '^/server': '/server'
  128. // }
  129. // },
  130. // '/object/': {
  131. // target: 'http://192.168.0.14:52010',
  132. // changeOrigin: true,
  133. // pathRewrite: {
  134. // '^/object': '/object'
  135. // }
  136. // },
  137. // '/mapServer/': {
  138. // target: 'http://192.168.0.14:52015',
  139. // changeOrigin: true,
  140. // pathRewrite: {
  141. // '^/mapServer': ''
  142. // }
  143. // }
  144. }
  145. },
  146. pluginOptions: {
  147. 'style-resources-loader': {
  148. preProcessor: 'scss',
  149. patterns: [
  150. path.resolve(__dirname, 'src/styles/_variables.scss'),
  151. path.resolve(__dirname, 'src/styles/_mixins.scss'),
  152. ]
  153. }
  154. },
  155. configureWebpack() {
  156. return {
  157. resolve: {
  158. alias: {
  159. '@': resolve('src'),
  160. '*': resolve(''),
  161. 'Assets': resolve('src/assets')
  162. }
  163. },
  164. module: {
  165. rules: [
  166. {
  167. test: /\.(json5?|ya?ml)$/, // target json, json5, yaml and yml files
  168. loader: '@intlify/vue-i18n-loader',
  169. include: [ // Use `Rule.include` to specify the files of locale messages to be pre-compiled
  170. path.resolve(__dirname, 'src/lang')
  171. ]
  172. },
  173. ],
  174. },
  175. plugins: isProduction ? [
  176. // new UglifyJsPlugin({
  177. // uglifyOptions: {
  178. // compress: {
  179. // drop_debugger: true,
  180. // drop_console: true, //生产环境自动删除console
  181. // },
  182. // warnings: false,
  183. // },
  184. // sourceMap: false,
  185. // parallel: true //使用多进程并行运行来提高构建速度。默认并发运行数:os.cpus().length - 1。
  186. // }),
  187. // 配置压缩
  188. new CompressionPlugin({
  189. // test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
  190. threshold: 1024 * 10, // 30K
  191. minRatio: 0.8,
  192. algorithm: 'gzip', // 使用gzip压缩
  193. test: /\.js$|\.css$/, // 匹配文件名
  194. filename: '[path].gz[query]', // 压缩后的文件名(保持原文件名,后缀加.gz)
  195. deleteOriginalAssets: false
  196. }),
  197. new WebpackBar({
  198. name: title
  199. })
  200. ] : [new WebpackBar({
  201. name: title
  202. })],
  203. // externals: isProduction ? {
  204. // 'vue': 'Vue',
  205. // 'vuex': 'Vuex',
  206. // 'vant' : 'vant',
  207. // 'vue-router': 'VueRouter',
  208. // 'echarts': 'echarts'
  209. // } : {}
  210. }
  211. },
  212. chainWebpack: config => {
  213. config.optimization.minimizer('terser').tap((args) => {
  214. args[0].parallel = 4
  215. args[0].terserOptions.compress.warnings = true
  216. args[0].terserOptions.compress.drop_debugger = true
  217. args[0].terserOptions.compress.drop_console = true
  218. return args
  219. })
  220. config.module
  221. .rule('ts')
  222. .use('ts-loader')
  223. .tap(options => {
  224. options = merge(options, {
  225. transpileOnly: true,
  226. getCustomTransformers: () => ({
  227. before: [
  228. tsImportPluginFactory({
  229. libraryName: 'vant',
  230. libraryDirectory: 'es',
  231. style: true
  232. })
  233. ]
  234. }),
  235. compilerOptions: {
  236. module: 'es2015'
  237. }
  238. })
  239. return options
  240. })
  241. }
  242. }