babel.config.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * @Author: PoJun
  3. * @Date: 2023-09-13 15:57:27
  4. * @LastEditors: PoJun
  5. * @LastEditTime: 2023-09-13 18:11:28
  6. * @Message: Nothing
  7. */
  8. const webpack = require("webpack");
  9. const plugins = [];
  10. if (process.env.UNI_OPT_TREESHAKINGNG) {
  11. plugins.push(require("@dcloudio/vue-cli-plugin-uni-optimize/packages/babel-plugin-uni-api/index.js"));
  12. }
  13. if (
  14. (process.env.UNI_PLATFORM === "app-plus" && process.env.UNI_USING_V8) ||
  15. (process.env.UNI_PLATFORM === "h5" && process.env.UNI_H5_BROWSER === "builtin")
  16. ) {
  17. const path = require("path");
  18. const isWin = /^win/.test(process.platform);
  19. const normalizePath = path => (isWin ? path.replace(/\\/g, "/") : path);
  20. const input = normalizePath(process.env.UNI_INPUT_DIR);
  21. try {
  22. plugins.push([
  23. require("@dcloudio/vue-cli-plugin-hbuilderx/packages/babel-plugin-console"),
  24. {
  25. file(file) {
  26. file = normalizePath(file);
  27. if (file.indexOf(input) === 0) {
  28. return path.relative(input, file);
  29. }
  30. return false;
  31. },
  32. },
  33. ]);
  34. } catch (e) {}
  35. }
  36. process.UNI_LIBRARIES = process.UNI_LIBRARIES || ["@dcloudio/uni-ui"];
  37. process.UNI_LIBRARIES.forEach(libraryName => {
  38. plugins.push([
  39. "import",
  40. {
  41. libraryName: libraryName,
  42. customName: name => {
  43. return `${libraryName}/lib/${name}/${name}`;
  44. },
  45. },
  46. ]);
  47. });
  48. if (process.env.UNI_PLATFORM !== "h5") {
  49. plugins.push("@babel/plugin-transform-runtime");
  50. }
  51. const config = {
  52. presets: [
  53. [
  54. "@vue/app",
  55. {
  56. modules: webpack.version[0] > 4 ? "auto" : "commonjs",
  57. useBuiltIns: process.env.UNI_PLATFORM === "h5" ? "usage" : "entry",
  58. },
  59. ],
  60. ],
  61. plugins,
  62. };
  63. const UNI_H5_TEST = "**/@dcloudio/uni-h5/dist/index.umd.min.js";
  64. if (process.env.NODE_ENV === "production") {
  65. config.overrides = [
  66. {
  67. test: UNI_H5_TEST,
  68. compact: true,
  69. },
  70. ];
  71. } else {
  72. config.ignore = [UNI_H5_TEST];
  73. }
  74. module.exports = config;