vue.config.js 6.4 KB

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