vue.config.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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: [
  15. "https://unpkg.com/vue@3.2.31/dist/vue.global.js",
  16. "https://unpkg.com/vue-router@4.0.14/dist/vue-router.global.js",
  17. "https://unpkg.com/vuex@4.0.2/dist/vuex.global.js",
  18. "https://cdn.jsdelivr.net/npm/vant@3/lib/vant.min.js",
  19. "https://cdn.jsdelivr.net/npm/echarts@5.3.2/dist/echarts.min.js"
  20. ]
  21. };
  22. const {
  23. publicPath,
  24. assetsDir,
  25. parallel,
  26. outputDir,
  27. lintOnSave,
  28. transpileDependencies,
  29. title,
  30. devPort
  31. } = require("./src/config/default/vue.custom.config");
  32. const CompressionPlugin = require("compression-webpack-plugin");
  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")({
  58. // 把px单位换算成rem单位
  59. rootValue: 96, // vant官方使用的是37.5
  60. minPixelValue: 4,
  61. unitPrecision: 3,
  62. selectorBlackList: ["mu"], // 忽略转换正则匹配项
  63. propList: ["*"]
  64. })
  65. ]
  66. }
  67. }
  68. },
  69. devServer: {
  70. hot: true,
  71. port: devPort,
  72. open: true,
  73. noInfo: false,
  74. overlay: {
  75. warnings: true,
  76. errors: true
  77. },
  78. proxy: {
  79. "/sgh5/duoduo-service/": {
  80. target: "https://duoduoenv.sagacloud.cn",
  81. // target: 'http://192.168.0.47:52015',
  82. changeOrigin: true,
  83. pathRewrite: {
  84. "^/sgh5/duoduo-service": "/duoduo-service"
  85. }
  86. },
  87. "/sgh5/pad_mtime": {
  88. target: "http://39.106.8.246:9091/",
  89. changeOrigin: true,
  90. pathRewrite: {
  91. "^/sgh5/pad_mtime": "/pad_mtime"
  92. }
  93. },
  94. "/sgh5/server/": {
  95. // target: 'https://duoduoenv.sagacloud.cn',
  96. target: "http://sso.sagacloud.cn",
  97. changeOrigin: true,
  98. pathRewrite: {
  99. "^/sgh5/server": "/server"
  100. }
  101. },
  102. "/sgh5/mngserver/": {
  103. // target: 'https://duoduoenv.sagacloud.cn',
  104. target: "http://mng.sagacloud.cn",
  105. changeOrigin: true,
  106. pathRewrite: {
  107. "^/sgh5/mngserver": "/server"
  108. }
  109. },
  110. "/sgh5/anon/": {
  111. // target: 'https://duoduoenv.sagacloud.cn',
  112. target: "http://mng.sagacloud.cn",
  113. changeOrigin: true,
  114. pathRewrite: {
  115. "^/sgh5/anon": "/anon"
  116. }
  117. },
  118. "/sgh5/test/": {
  119. // target: 'https://duoduoenv.sagacloud.cn',
  120. target: "http://192.168.88.6:52009", // 永琪
  121. // target: 'http://192.168.4.54:52009', // 小静
  122. // target: 'http://192.168.16.168:52015',
  123. changeOrigin: true,
  124. pathRewrite: {
  125. "^/sgh5/test": ""
  126. }
  127. },
  128. "/sgh5/test1/": {
  129. // target: 'https://duoduoenv.sagacloud.cn',
  130. target: "http://192.168.0.65:52009",
  131. changeOrigin: true,
  132. pathRewrite: {
  133. "^/sgh5/test1": ""
  134. }
  135. }
  136. // '/api': {
  137. // target: 'http://api.sagacloud.cn',
  138. // changeOrigin: true,
  139. // pathRewrite: {
  140. // '^/api': ''
  141. // }
  142. // },
  143. // '/duoduo-service/': {
  144. // target: 'https://duoduoenv.sagacloud.cn',
  145. // changeOrigin: true,
  146. // pathRewrite: {
  147. // '^/duoduo-service': '/duoduo-service'
  148. // }
  149. // },
  150. // '/server/': {
  151. // target: 'https://duoduoenv.sagacloud.cn',
  152. // changeOrigin: true,
  153. // pathRewrite: {
  154. // '^/server': '/server'
  155. // }
  156. // },
  157. // '/object/': {
  158. // target: 'http://192.168.0.14:52010',
  159. // changeOrigin: true,
  160. // pathRewrite: {
  161. // '^/object': '/object'
  162. // }
  163. // },
  164. // '/mapServer/': {
  165. // target: 'http://192.168.0.14:52015',
  166. // changeOrigin: true,
  167. // pathRewrite: {
  168. // '^/mapServer': ''
  169. // }
  170. // }
  171. }
  172. },
  173. pluginOptions: {
  174. "style-resources-loader": {
  175. preProcessor: "scss",
  176. patterns: [
  177. path.resolve(__dirname, "src/styles/_variables.scss"),
  178. path.resolve(__dirname, "src/styles/_mixins.scss")
  179. ]
  180. }
  181. },
  182. configureWebpack() {
  183. return {
  184. resolve: {
  185. alias: {
  186. "@": resolve("src"),
  187. "*": resolve(""),
  188. Assets: resolve("src/assets")
  189. }
  190. },
  191. module: {
  192. rules: [
  193. {
  194. test: /\.(json5?|ya?ml)$/, // target json, json5, yaml and yml files
  195. loader: "@intlify/vue-i18n-loader",
  196. include: [
  197. // Use `Rule.include` to specify the files of locale messages to be pre-compiled
  198. path.resolve(__dirname, "src/lang")
  199. ]
  200. }
  201. ]
  202. },
  203. plugins: isProduction
  204. ? [
  205. new UglifyJsPlugin({
  206. uglifyOptions: {
  207. compress: {
  208. drop_debugger: true,
  209. drop_console: true //生产环境自动删除console
  210. },
  211. warnings: false
  212. },
  213. sourceMap: false,
  214. parallel: true //使用多进程并行运行来提高构建速度。默认并发运行数:os.cpus().length - 1。
  215. }),
  216. // 配置压缩
  217. new CompressionPlugin({
  218. test: new RegExp(
  219. "\\.(" + productionGzipExtensions.join("|") + ")$"
  220. ),
  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. ]
  232. : [
  233. new WebpackBar({
  234. name: title
  235. })
  236. ]
  237. // externals: isProduction ? {
  238. // 'vue': 'Vue',
  239. // 'vuex': 'Vuex',
  240. // 'vant' : 'vant',
  241. // 'vue-router': 'VueRouter',
  242. // 'echarts': 'echarts'
  243. // } : {}
  244. };
  245. },
  246. chainWebpack: config => {
  247. config.plugins.delete("preload");
  248. config.plugins.delete("prefetch");
  249. config.optimization.minimizer("terser").tap(args => {
  250. args[0].parallel = 4;
  251. args[0].terserOptions.compress.warnings = true;
  252. args[0].terserOptions.compress.drop_debugger = true;
  253. args[0].terserOptions.compress.drop_console = true;
  254. return args;
  255. });
  256. config.module
  257. .rule("ts")
  258. .use("ts-loader")
  259. .tap(options => {
  260. options = merge(options, {
  261. transpileOnly: true,
  262. getCustomTransformers: () => ({
  263. before: [
  264. tsImportPluginFactory({
  265. libraryName: "vant",
  266. libraryDirectory: "es",
  267. style: true
  268. })
  269. ]
  270. }),
  271. compilerOptions: {
  272. module: "es2015"
  273. }
  274. });
  275. return options;
  276. });
  277. }
  278. };