vue.config.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. const TransformPages = require("uni-read-pages");
  2. const execSync = require("child_process").execSync;
  3. const { webpack } = new TransformPages();
  4. module.exports = {
  5. productionSourceMap: true,
  6. transpileDependencies: ["@dcloudio/uni-ui"],
  7. configureWebpack: {
  8. plugins: [
  9. new webpack.DefinePlugin({
  10. ROUTES: webpack.DefinePlugin.runtimeValue(() => {
  11. const tfPages = new TransformPages({
  12. includes: ["path", "name", "meta", "aliasPath"],
  13. });
  14. return JSON.stringify(tfPages.routes);
  15. }, true),
  16. }),
  17. ],
  18. },
  19. chainWebpack: (config) => {
  20. const gitShortKey = execSync("git rev-parse --short HEAD")
  21. .toString()
  22. .trim();
  23. config.module.rule("svg").uses.clear();
  24. config.module
  25. .rule("svg")
  26. .set("type", void 0)
  27. .set("generator", void 0)
  28. .use("raw")
  29. .loader("raw-loader")
  30. .end();
  31. config.plugin("define").tap((args) => {
  32. // mbridge 中的 ENV,不加会打包所有 ENV
  33. if (Array.isArray(args)) {
  34. args.forEach((item) => {
  35. if (item && item["process.env"]) {
  36. item["process.env"] = Object.assign(item["process.env"], {
  37. ENV: JSON.stringify(""),
  38. VUE_APP_SENTRY_RELEASE: JSON.stringify(gitShortKey),
  39. VUE_APP_API_ORIGIN: JSON.stringify(
  40. process.env.VUE_APP_API_ORIGIN ||
  41. (process.env.NODE_ENV === "production"
  42. ? "https://www.ex.com"
  43. : process.env.UNI_PLATFORM !== "h5"
  44. ? "https://test.ex.com"
  45. : "")
  46. ),
  47. });
  48. }
  49. });
  50. }
  51. return args;
  52. });
  53. // process.exit(0);
  54. },
  55. };