@vuebro/loader-sfc 2.3.14 → 2.3.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,19 +1,11 @@
1
- import { compileStyleAsync, compileTemplate, compileScript, parse, } from "vue/compiler-sfc";
2
1
  import { consola } from "consola/browser";
3
- import { transform } from "sucrase";
4
2
  import hash from "hash-sum";
5
- const fetching = async (input, resolver = "text") => {
3
+ import { ofetch } from "ofetch";
4
+ import { transform } from "sucrase";
5
+ import { compileScript, compileStyleAsync, compileTemplate, parse, } from "vue/compiler-sfc";
6
+ const fetching = async (input) => {
6
7
  try {
7
- const response = await fetch(input);
8
- if (response.ok) {
9
- const method = response[resolver];
10
- if (typeof method === "function")
11
- return await method();
12
- else
13
- throw new Error(`Invalid resolver "${resolver}"`);
14
- }
15
- else
16
- throw new Error(`Response status: ${response.status.toString()}`);
8
+ return await ofetch(input);
17
9
  }
18
10
  catch (error) {
19
11
  consola.error(error);
@@ -27,32 +19,32 @@ const fetching = async (input, resolver = "text") => {
27
19
  URL.revokeObjectURL(objectURL);
28
20
  }
29
21
  };
30
- export default async (filename, { scriptOptions: { templateOptions: { compilerOptions: { expressionPlugins, ...restCompilerOptions } = {}, ...restTemplateOptions } = {}, ...restScriptOptions } = {}, parseOptions, styleOptions, } = {}) => {
22
+ export default async (filename, { parseOptions, scriptOptions: { templateOptions: { compilerOptions: { expressionPlugins, ...restCompilerOptions } = {}, ...restTemplateOptions } = {}, ...restScriptOptions } = {}, styleOptions, } = {}) => {
31
23
  const id = `data-v-${hash(filename)}`;
32
- const { errors: parseErrors, descriptor } = parse((await fetching(filename)) ?? "<template></template>", { filename, ...parseOptions });
33
- const { scriptSetup, template, slotted, script, styles } = descriptor;
24
+ const { descriptor, errors: parseErrors } = parse((await fetching(filename)) ?? "<template></template>", { filename, ...parseOptions });
25
+ const { script, scriptSetup, slotted, styles, template } = descriptor;
34
26
  const langs = new Set([script, scriptSetup]
35
27
  .filter((scriptBlock) => scriptBlock !== null)
36
28
  .flatMap(({ lang = "js" }) => [
37
29
  ...(/[jt]sx$/.test(lang) ? ["jsx"] : []),
38
30
  ...(/tsx?$/.test(lang) ? ["typescript"] : []),
39
- ])), { content: source = "", ast } = template ?? {};
31
+ ])), { ast, content: source = "" } = template ?? {};
40
32
  let styleWarning = "";
41
33
  const styleErrors = [];
42
34
  const style = !(document.getElementById(id) instanceof HTMLStyleElement)
43
- ? Promise.all(styles.map(async ({ scoped = false, content, module, src }) => {
35
+ ? Promise.all(styles.map(async ({ content, module, scoped = false, src }) => {
44
36
  const modules = !!module;
45
37
  if (modules && !styleWarning) {
46
38
  styleWarning = "<style module> is not supported in the playground.";
47
39
  return "";
48
40
  }
49
41
  else {
50
- const { errors, code } = await compileStyleAsync({
51
- source: src ? ((await fetching(src)) ?? "") : content,
42
+ const { code, errors } = await compileStyleAsync({
52
43
  filename,
44
+ id,
53
45
  modules,
54
46
  scoped,
55
- id,
47
+ source: src ? ((await fetching(src)) ?? "") : content,
56
48
  ...styleOptions,
57
49
  });
58
50
  styleErrors.push(...errors);
@@ -64,34 +56,34 @@ export default async (filename, { scriptOptions: { templateOptions: { compilerOp
64
56
  expressionPlugins: [
65
57
  ...new Set([...(expressionPlugins ?? []), ...langs]),
66
58
  ],
67
- scopeId: id,
68
59
  filename,
60
+ scopeId: id,
69
61
  slotted,
70
62
  ...restCompilerOptions,
71
63
  }, templateOptions = {
72
- scoped: styles.some(({ scoped }) => scoped),
73
64
  compilerOptions,
74
65
  filename,
75
- slotted,
76
66
  id,
67
+ scoped: styles.some(({ scoped }) => scoped),
68
+ slotted,
77
69
  ...restTemplateOptions,
78
70
  }, scriptOptions = {
79
- templateOptions,
80
71
  id,
72
+ templateOptions,
81
73
  ...restScriptOptions,
82
74
  }, sucraseOptions = {
83
- transforms: [...langs],
84
75
  jsxRuntime: "preserve",
76
+ transforms: [...langs],
85
77
  };
86
- const { warnings: scriptWarnings, bindings, content, } = script || scriptSetup ? compileScript(descriptor, scriptOptions) : {};
78
+ const { bindings, content, warnings: scriptWarnings, } = script || scriptSetup ? compileScript(descriptor, scriptOptions) : {};
87
79
  if (bindings)
88
80
  compilerOptions.bindingMetadata = bindings;
89
- const { errors: templateErrors, tips: templateTips, code, } = template && (!scriptSetup || !scriptOptions.inlineTemplate)
81
+ const { code, errors: templateErrors, tips: templateTips, } = template && (!scriptSetup || !scriptOptions.inlineTemplate)
90
82
  ? compileTemplate({
91
83
  ...ast,
92
84
  filename,
93
- source,
94
85
  id,
86
+ source,
95
87
  ...templateOptions,
96
88
  })
97
89
  : {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vuebro/loader-sfc",
3
- "version": "2.3.14",
3
+ "version": "2.3.16",
4
4
  "description": "Vue3 Single File Component (SFC) loader. Load .vue files directly from your browser without any build step.",
5
5
  "keywords": [
6
6
  "vue",
@@ -41,6 +41,6 @@
41
41
  "@rollup/plugin-terser": "^0.4.4",
42
42
  "@types/hash-sum": "^1.0.2",
43
43
  "@types/node": "^24.9.1",
44
- "@vuebro/configs": "^1.1.41"
44
+ "@vuebro/configs": "^1.1.51"
45
45
  }
46
46
  }