vue.config.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. "use strict";
  2. const path = require("path");
  3. const defaultSettings = require("./src/settings.js");
  4. function resolve(dir) {
  5. return path.join(__dirname, dir);
  6. }
  7. const name = defaultSettings.title || "歌莉娅AI口播视频管理平台"; // 标题
  8. const port = process.env.port || process.env.npm_config_port || 9557; // 开发接口
  9. // 所有配置项描述 查看: https://cli.vuejs.org/config/
  10. module.exports = {
  11. publicPath: "./", // 基本路径
  12. outputDir: "dist", // 输出文件目录
  13. assetsDir: "static", // 放置生成的静态资源 (js、css、img、fonts) 的 (相对于 outputDir 的) 目录。
  14. // 指定生成的 index.html 的输出路径 (相对于 outputDir)。也可以是一个绝对路径
  15. // indexPath: './',
  16. lintOnSave: process.env.NODE_ENV === "production", // lintOnSave: eslint-loader 是否在保存的时候检查
  17. productionSourceMap: false, // 生产环境是否生成 sourceMap 文件
  18. devServer: {
  19. port: port,
  20. // open: true,
  21. overlay: {
  22. warnings: false,
  23. errors: true
  24. },
  25. public: "0.0.0.0:9557", //可以实现热部署
  26. proxy: {
  27. "/": {
  28. // target: "http://10.41.3.106:9093",
  29. target: "https://portal.gloria.com.cn",
  30. changeOrigin: true
  31. },
  32. }
  33. },
  34. // webpack配置
  35. configureWebpack: {
  36. name: name,
  37. resolve: {
  38. alias: {
  39. "@": resolve("src")
  40. }
  41. }
  42. },
  43. chainWebpack(config) {
  44. // 删除预加载
  45. config.plugins.delete("preload"); // TODO: need test
  46. config.plugins.delete("prefetch"); // TODO: need test
  47. // set svg-sprite-loader
  48. config.module
  49. .rule("svg")
  50. .exclude.add(resolve("src/icons"))
  51. .end();
  52. config.module
  53. .rule("icons")
  54. .test(/\.svg$/)
  55. .include.add(resolve("src/icons"))
  56. .end()
  57. .use("svg-sprite-loader")
  58. .loader("svg-sprite-loader")
  59. .options({
  60. symbolId: "icon-[name]"
  61. })
  62. .end();
  63. // set preserveWhitespace
  64. config.module
  65. .rule("vue")
  66. .use("vue-loader")
  67. .loader("vue-loader")
  68. .tap(options => {
  69. options.compilerOptions.preserveWhitespace = true;
  70. return options;
  71. })
  72. .end();
  73. config
  74. // https://webpack.js.org/configuration/devtool/#development
  75. .when(process.env.NODE_ENV === "development", config =>
  76. config.devtool("cheap-source-map")
  77. );
  78. config.when(process.env.NODE_ENV !== "development", config => {
  79. //非开发环境
  80. config
  81. .plugin("ScriptExtHtmlWebpackPlugin")
  82. .after("html")
  83. .use("script-ext-html-webpack-plugin", [
  84. {
  85. // `runtime` must same as runtimeChunk name. default is `runtime`
  86. inline: /runtime\..*\.js$/
  87. }
  88. ])
  89. .end();
  90. // 分割代码
  91. config.optimization.splitChunks({
  92. chunks: "all",
  93. cacheGroups: {
  94. libs: {
  95. name: "chunk-libs",
  96. test: /[\\/]node_modules[\\/]/,
  97. priority: 10,
  98. chunks: "initial" // only package third parties that are initially dependent
  99. },
  100. elementUI: {
  101. name: "chunk-elementUI", // split elementUI into a single package
  102. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  103. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  104. },
  105. commons: {
  106. name: "chunk-commons",
  107. test: resolve("src/components"), // can customize your rules
  108. minChunks: 3, // minimum common number
  109. priority: 5,
  110. reuseExistingChunk: false
  111. }
  112. }
  113. });
  114. config.optimization.runtimeChunk("single");
  115. });
  116. }
  117. };