importPlugin.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.importPlugin = void 0;
  4. const path_1 = require("path");
  5. const loader_shared_1 = require("@vuetify/loader-shared");
  6. const url_1 = require("url");
  7. function parseId(id) {
  8. const { query, pathname } = (0, url_1.parse)(id);
  9. return {
  10. query: query ? Object.fromEntries(new url_1.URLSearchParams(query)) : null,
  11. path: pathname !== null && pathname !== void 0 ? pathname : id
  12. };
  13. }
  14. function importPlugin() {
  15. return {
  16. name: 'vuetify:import',
  17. configResolved(config) {
  18. if (config.plugins.findIndex(plugin => plugin.name === 'vuetify:import') < config.plugins.findIndex(plugin => plugin.name === 'vite:vue')) {
  19. throw new Error('Vuetify plugin must be loaded after the vue plugin');
  20. }
  21. },
  22. async transform(code, id) {
  23. const { query, path } = parseId(id);
  24. if (((!query || !('vue' in query)) && (0, path_1.extname)(path) === '.vue' && !/^import { render as _sfc_render } from ".*"$/m.test(code)) ||
  25. (query && 'vue' in query && (query.type === 'template' || (query.type === 'script' && query.setup === 'true')))) {
  26. const { code: imports, source } = (0, loader_shared_1.generateImports)(code);
  27. return {
  28. code: source + imports,
  29. map: null,
  30. };
  31. }
  32. return null;
  33. }
  34. };
  35. }
  36. exports.importPlugin = importPlugin;
  37. //# sourceMappingURL=importPlugin.js.map