babel.config.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. const plugins = [];
  2. if (process.env.UNI_OPT_TREESHAKINGNG) {
  3. plugins.push(
  4. require("@dcloudio/vue-cli-plugin-uni-optimize/packages/babel-plugin-uni-api/index.js")
  5. );
  6. }
  7. if (process.env.UNI_PLATFORM === "app-plus" && process.env.UNI_USING_V8) {
  8. const path = require("path");
  9. const isWin = /^win/.test(process.platform);
  10. const normalizePath = path => (isWin ? path.replace(/\\/g, "/") : path);
  11. const input = normalizePath(process.env.UNI_INPUT_DIR);
  12. try {
  13. plugins.push([
  14. require("@dcloudio/vue-cli-plugin-hbuilderx/packages/babel-plugin-console"),
  15. {
  16. file(file) {
  17. file = normalizePath(file);
  18. if (file.indexOf(input) === 0) {
  19. return path.relative(input, file);
  20. }
  21. return false;
  22. }
  23. }
  24. ]);
  25. } catch (e) {}
  26. }
  27. process.UNI_LIBRARIES = process.UNI_LIBRARIES || ["@dcloudio/uni-ui"];
  28. process.UNI_LIBRARIES.forEach(libraryName => {
  29. plugins.push([
  30. "import",
  31. {
  32. libraryName: libraryName,
  33. customName: name => {
  34. return `${libraryName}/lib/${name}/${name}`;
  35. }
  36. }
  37. ]);
  38. });
  39. module.exports = {
  40. presets: [
  41. [
  42. "@vue/app",
  43. {
  44. modules: process.env.UNI_PLATFORM === "h5" ? "auto" : "commonjs",
  45. useBuiltIns: process.env.UNI_PLATFORM === "h5" ? "usage" : "entry"
  46. }
  47. ]
  48. ],
  49. ignore: ["./src/pagesOrder/js/**/*.js"],
  50. plugins
  51. };