vue.config.js 6.8 KB

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