vue.config.js 7.7 KB

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