vue.config.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. const { defineConfig } = require("@vue/cli-service");
  2. const dayjs = require("dayjs");
  3. const { name, version, chineseName } = require("./package.json");
  4. const buildTag = `${dayjs(Date.now()).format("YYYY-MM-DD HH:mm:ss")}`;
  5. const injectScript = `<script>const aVersionInfo = { name: '${name}', chineseName: '${chineseName}', version: '${version}', buildDate:'${buildTag}' }; if (!window.versionInfo) {window.versionInfo = {};} window.versionInfo['${name}'] = aVersionInfo;</script>`;
  6. const rootId = name + "__id";
  7. module.exports = defineConfig({
  8. transpileDependencies: true,
  9. publicPath: "./",
  10. devServer: {
  11. host: "0.0.0.0",
  12. https: {
  13. key: "./cert/localhost+1-key.pem",
  14. cert: "./cert/localhost+1.pem",
  15. },
  16. hot: true,
  17. port: 8332,
  18. headers: {
  19. "Access-Control-Allow-Origin": "*",
  20. },
  21. },
  22. configureWebpack: {
  23. output: {
  24. library: name,
  25. libraryTarget: "umd", // 把微应用打包成 umd 库格式
  26. chunkLoadingGlobal: `webpackJsonp_${name}`, // webpack4 => jsonpFunction
  27. },
  28. plugins: [],
  29. },
  30. chainWebpack: (config) => {
  31. config.plugin("html").tap((args) => {
  32. if (args && args.length > 0) {
  33. args[0].rootId = rootId;
  34. args[0].customInjectScript = injectScript;
  35. }
  36. return args;
  37. });
  38. },
  39. });