vue.config.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * @Date: 2023-06-18 10:09:15
  3. * @LastEditors: zhubj
  4. * @LastEditTime: 2023-06-19 10:49:41
  5. * @Description: 头部注释
  6. * @FilePath: \own-vue3-vuecli-template\vue.config.js
  7. */
  8. 'use strict'
  9. const path = require('path')
  10. function resolve(dir) {
  11. return path.join(__dirname, dir)
  12. }
  13. const { defineConfig } = require('@vue/cli-service')
  14. const name = process.env.VUE_APP_TITLE || '网页标题' // 网页标题
  15. const port = process.env.port || process.env.npm_config_port || 8011 // 端口
  16. // element-plus 按需导入自动导入的插件
  17. const AutoImport = require('unplugin-auto-import/webpack')
  18. const Components = require('unplugin-vue-components/webpack')
  19. const { ElementPlusResolver } = require('unplugin-vue-components/resolvers')
  20. // 实现 gzip 压缩打包
  21. const CompressionPlugin = require('compression-webpack-plugin')
  22. module.exports = defineConfig({
  23. // 默认情况下,Vue CLI 会假设你的应用是被部署在一个域名的根路径上
  24. // 例如 https://www.my-app.com/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径
  25. // 例如,如果你的应用被部署在 https://www.my-app.com/my-app/,则设置 publicPath 为 /my-app/
  26. publicPath: process.env.NODE_ENV === "production" ? "/" : "/",
  27. // 当运行 vue-cli-service build 时生成的生产环境构建文件的目录。注意目标目录的内容在构建之前会被清除 (构建时传入 --no-clean 可关闭该行为)。
  28. outputDir: 'dist',
  29. // 放置生成的静态资源 (js、css、img、fonts) 的 (相对于 outputDir 的) 目录
  30. assetsDir: 'static',
  31. // 如果你不需要生产环境的 source map,可以将其设置为 false 以加速生产环境构建。
  32. productionSourceMap: false,
  33. // 默认情况下 babel-loader 会忽略所有 node_modules 中的文件。你可以启用本选项,以避免构建后的代码中出现未转译的第三方依赖(对所有的依赖都进行转译可能会降低构建速度)
  34. transpileDependencies: false,
  35. // webpack-dev-server 相关配置
  36. devServer: {
  37. host: '0.0.0.0',
  38. port: port,
  39. open: true,
  40. proxy: {
  41. // detail: https://cli.vuejs.org/config/#devserver-proxy
  42. // [process.env.VUE_APP_GENERAT_URL]: {
  43. // // target: 'http://123.60.219.66:9002',
  44. // target: 'http://192.168.2.12:9002',
  45. // changeOrigin: true, //开启代理
  46. // pathRewrite: {
  47. // [process.env.VUE_APP_GENERAT_URL]: ''
  48. // }
  49. // },
  50. // [process.env.VUE_APP_BASE_URL]: {
  51. // target: 'http://123.60.219.66:8086',
  52. // changeOrigin: true,
  53. // pathRewrite: {
  54. // [process.env.VUE_APP_BASE_URL]: ''
  55. // }
  56. // }
  57. }
  58. },
  59. // 和webpapck属性完全一致,最后会进行合并
  60. configureWebpack:{
  61. name: name,
  62. resolve: {
  63. alias: {
  64. '@': resolve('src'),
  65. '@tools': resolve('./src/tools'),
  66. '@api': resolve('./src/api'),
  67. '@com': resolve('./src/components'),
  68. },
  69. fallback: {
  70. "https": false,
  71. "zlib": false,
  72. "http": false,
  73. "url": false
  74. },
  75. mainFiles: ['index', 'Cesium']
  76. },
  77. //配置webpack自动按需引入element-plus
  78. plugins: [
  79. AutoImport({
  80. resolvers: [ElementPlusResolver()],
  81. }),
  82. Components({
  83. resolvers: [ElementPlusResolver()],
  84. }),
  85. // http://doc.ruoyi.vip/ruoyi-vue/other/faq.html#使用gzip解压缩静态文件
  86. new CompressionPlugin({
  87. test: /\.(js|css|html)?$/i, // 压缩文件格式
  88. filename: '[path][base].gz', // 压缩后的文件名
  89. algorithm: 'gzip', // 使用gzip压缩
  90. threshold: 10240, // 最小文件开启压缩
  91. minRatio: 0.8 // 压缩率小于1才会压缩
  92. })
  93. ],
  94. }
  95. })