vue.config.js 7.8 KB

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