版博士V2.0程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

chunk-ZQZG2Y5V.mjs 1.6 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import {
  2. transformBetterDefine
  3. } from "./chunk-W5ODBUYZ.mjs";
  4. // src/index.ts
  5. import { createUnplugin } from "unplugin";
  6. import {
  7. REGEX_SETUP_SFC,
  8. REGEX_VUE_SFC,
  9. REGEX_VUE_SUB,
  10. createFilter,
  11. detectVueVersion
  12. } from "@vue-macros/common";
  13. import { RollupResolve, setResolveTSFileIdImpl } from "@vue-macros/api";
  14. function resolveOptions(options, framework) {
  15. const version = options.version || detectVueVersion();
  16. return {
  17. include: [REGEX_VUE_SFC, REGEX_SETUP_SFC].concat(
  18. version === 2 && framework === "webpack" ? REGEX_VUE_SUB : []
  19. ),
  20. isProduction: process.env.NODE_ENV === "production",
  21. ...options,
  22. version
  23. };
  24. }
  25. var name = "unplugin-vue-better-define";
  26. var src_default = createUnplugin(
  27. (userOptions = {}, { framework }) => {
  28. const options = resolveOptions(userOptions, framework);
  29. const filter = createFilter(options);
  30. const { resolve, handleHotUpdate } = RollupResolve();
  31. return {
  32. name,
  33. enforce: "pre",
  34. buildStart() {
  35. if (framework === "rollup" || framework === "vite") {
  36. setResolveTSFileIdImpl(resolve(this));
  37. }
  38. },
  39. transformInclude(id) {
  40. return filter(id);
  41. },
  42. async transform(code, id) {
  43. try {
  44. return await transformBetterDefine(code, id, options.isProduction);
  45. } catch (err) {
  46. this.warn(`${name} ${err}`);
  47. console.warn(err);
  48. }
  49. },
  50. vite: {
  51. configResolved(config) {
  52. options.isProduction = config.isProduction;
  53. },
  54. handleHotUpdate
  55. }
  56. };
  57. }
  58. );
  59. export {
  60. src_default
  61. };