zhongshujie
5 天以前 bb584963c6abe77c5577cbcad3c9956b69444ae9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const { defineConfig } = require("@vue/cli-service");
const webpack = require("webpack");
// 获取所有书籍列表
const bookList = process.env.VUE_APP_BOOK_LIST
  ? process.env.VUE_APP_BOOK_LIST.split("/")
  : [];
const publicPath = process.env.VUE_APP_PUBLIC_PATH;
module.exports = defineConfig({
  publicPath: process.env.VUE_APP_PUBLIC_PATH,
  transpileDependencies: true,
  lintOnSave: false,
  devServer: {
    open: true,
    historyApiFallback: true,
    allowedHosts: "all",
    headers: {
      "access-control-allow-origin": "*",
    },
    client: {
      overlay: { warnings: false, errors: true },
    },
  },
  configureWebpack: {
    output: {
      library: `app-content`,
      libraryTarget: "umd",
      chunkLoadingGlobal: `webpackJsonp_app-content`,
    },
    plugins: [
      new webpack.IgnorePlugin({
        checkResource(resource) {
          if (process.env.VUE_APP_ENV == "product") {
            // 编译和打包过滤
            for (let i = 0; i < bookList.length; i++) {
              const bookName = bookList[i];
              if (bookName != process.env.VUE_APP_BOOK_ID) {
                // 过滤不需要的模块
                if (resource.indexOf(bookName) > -1) {
                  return true;
                }
              }
            }
          }
          return false;
        },
      }),
    ],
  },
  chainWebpack: (config) => {
    config.module
      .rule("change-prefix")
      .test(/\.js$/)
      .include.add("/node_modules/element-ui/lib")
      .end()
      .use("change-prefix")
      .loader("change-prefix-loader")
      .options({
        prefix: "el-",
        replace: "gp-",
      })
      .end();
  //   config.module
  //     .rule("fonts")
  //     .test(/.(woff|woff2|eot|ttf|otf|TTF)$/)
  //     .type("asset/resource")
  //     .use("file-loader")
  //     .loader("file-loader")
  //     .options({
  //       name: "fonts/[name].[hash:8].[ext]", // 输出到 dist/fonts/ 目录
  //       publicPath: publicPath, // 确保 publicPath 正确
  //       limit: 0,
  //     });
   },
});