@vuebro/loader-sfc 2.3.15 → 2.3.17

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,9 +1,16 @@
1
- import { compileStyleAsync, compileTemplate, compileScript, parse, } from "vue/compiler-sfc";
2
1
  import { consola } from "consola/browser";
3
- import { transform } from "sucrase";
4
- import { ofetch } from "ofetch";
5
2
  import hash from "hash-sum";
6
- const inject = async (code) => {
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) => {
7
+ try {
8
+ return await ofetch(input);
9
+ }
10
+ catch (error) {
11
+ consola.error(error);
12
+ }
13
+ }, inject = async (code) => {
7
14
  const objectURL = URL.createObjectURL(new Blob([code], { type: "application/javascript" }));
8
15
  try {
9
16
  return (await import(objectURL));
@@ -11,40 +18,33 @@ const inject = async (code) => {
11
18
  finally {
12
19
  URL.revokeObjectURL(objectURL);
13
20
  }
14
- }, fetching = async (input) => {
15
- try {
16
- return await ofetch(input);
17
- }
18
- catch (error) {
19
- consola.error(error);
20
- }
21
21
  };
22
- 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, } = {}) => {
23
23
  const id = `data-v-${hash(filename)}`;
24
- const { errors: parseErrors, descriptor } = parse((await fetching(filename)) ?? "<template></template>", { filename, ...parseOptions });
25
- 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;
26
26
  const langs = new Set([script, scriptSetup]
27
27
  .filter((scriptBlock) => scriptBlock !== null)
28
28
  .flatMap(({ lang = "js" }) => [
29
29
  ...(/[jt]sx$/.test(lang) ? ["jsx"] : []),
30
30
  ...(/tsx?$/.test(lang) ? ["typescript"] : []),
31
- ])), { content: source = "", ast } = template ?? {};
31
+ ])), { ast, content: source = "" } = template ?? {};
32
32
  let styleWarning = "";
33
33
  const styleErrors = [];
34
34
  const style = !(document.getElementById(id) instanceof HTMLStyleElement)
35
- ? Promise.all(styles.map(async ({ scoped = false, content, module, src }) => {
35
+ ? Promise.all(styles.map(async ({ content, module, scoped = false, src }) => {
36
36
  const modules = !!module;
37
37
  if (modules && !styleWarning) {
38
38
  styleWarning = "<style module> is not supported in the playground.";
39
39
  return "";
40
40
  }
41
41
  else {
42
- const { errors, code } = await compileStyleAsync({
43
- source: src ? ((await fetching(src)) ?? "") : content,
42
+ const { code, errors } = await compileStyleAsync({
44
43
  filename,
44
+ id,
45
45
  modules,
46
46
  scoped,
47
- id,
47
+ source: src ? ((await fetching(src)) ?? "") : content,
48
48
  ...styleOptions,
49
49
  });
50
50
  styleErrors.push(...errors);
@@ -56,34 +56,34 @@ export default async (filename, { scriptOptions: { templateOptions: { compilerOp
56
56
  expressionPlugins: [
57
57
  ...new Set([...(expressionPlugins ?? []), ...langs]),
58
58
  ],
59
- scopeId: id,
60
59
  filename,
60
+ scopeId: id,
61
61
  slotted,
62
62
  ...restCompilerOptions,
63
63
  }, templateOptions = {
64
- scoped: styles.some(({ scoped }) => scoped),
65
64
  compilerOptions,
66
65
  filename,
67
- slotted,
68
66
  id,
67
+ scoped: styles.some(({ scoped }) => scoped),
68
+ slotted,
69
69
  ...restTemplateOptions,
70
70
  }, scriptOptions = {
71
- templateOptions,
72
71
  id,
72
+ templateOptions,
73
73
  ...restScriptOptions,
74
74
  }, sucraseOptions = {
75
- transforms: [...langs],
76
75
  jsxRuntime: "preserve",
76
+ transforms: [...langs],
77
77
  };
78
- const { warnings: scriptWarnings, bindings, content, } = script || scriptSetup ? compileScript(descriptor, scriptOptions) : {};
78
+ const { bindings, content, warnings: scriptWarnings, } = script || scriptSetup ? compileScript(descriptor, scriptOptions) : {};
79
79
  if (bindings)
80
80
  compilerOptions.bindingMetadata = bindings;
81
- const { errors: templateErrors, tips: templateTips, code, } = template && (!scriptSetup || !scriptOptions.inlineTemplate)
81
+ const { code, errors: templateErrors, tips: templateTips, } = template && (!scriptSetup || !scriptOptions.inlineTemplate)
82
82
  ? compileTemplate({
83
83
  ...ast,
84
84
  filename,
85
- source,
86
85
  id,
86
+ source,
87
87
  ...templateOptions,
88
88
  })
89
89
  : {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vuebro/loader-sfc",
3
- "version": "2.3.15",
3
+ "version": "2.3.17",
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",
@@ -34,13 +34,18 @@
34
34
  },
35
35
  "prettier": "@vuebro/configs/prettierrc",
36
36
  "dependencies": {
37
+ "consola": "^3.4.2",
37
38
  "hash-sum": "^2.0.0",
38
- "sucrase": "^3.35.0"
39
+ "ofetch": "^1.5.1",
40
+ "sucrase": "^3.35.0",
41
+ "vue": "^3.5.22"
39
42
  },
40
43
  "devDependencies": {
41
44
  "@rollup/plugin-terser": "^0.4.4",
42
45
  "@types/hash-sum": "^1.0.2",
43
- "@types/node": "^24.9.1",
44
- "@vuebro/configs": "^1.1.42"
46
+ "@types/node": "^24.9.2",
47
+ "@vuebro/configs": "^1.1.54",
48
+ "eslint": "^9.39.0",
49
+ "vite": "^7.1.12"
45
50
  }
46
51
  }