@vuebro/loader-sfc 2.0.1 → 2.0.3
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.
- package/dist/loader-sfc.d.ts +2 -2
- package/dist/loader-sfc.esm-browser.prod.js +21248 -21249
- package/dist/loader-sfc.js +41 -36
- package/package.json +7 -7
package/dist/loader-sfc.js
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
1
|
-
import { compileScript, compileStyleAsync, compileTemplate, parse, } from "@vue/compiler-sfc";
|
|
2
1
|
import hash from "hash-sum";
|
|
3
2
|
import { transform } from "sucrase";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
console.log(msg);
|
|
7
|
-
});
|
|
8
|
-
}, options = {
|
|
9
|
-
jsxRuntime: "preserve",
|
|
10
|
-
transforms: ["jsx", "typescript"],
|
|
11
|
-
};
|
|
3
|
+
import { compileScript, compileStyleAsync, compileTemplate, parse, } from "vue/compiler-sfc";
|
|
4
|
+
/* -------------------------------------------------------------------------- */
|
|
12
5
|
const fetchText = async (url) => {
|
|
13
6
|
try {
|
|
14
7
|
const response = await fetch(url);
|
|
@@ -21,49 +14,61 @@ const fetchText = async (url) => {
|
|
|
21
14
|
const objectURL = URL.createObjectURL(new Blob([code], { type: "application/javascript" })), value = (await import(objectURL));
|
|
22
15
|
URL.revokeObjectURL(objectURL);
|
|
23
16
|
return value;
|
|
24
|
-
},
|
|
17
|
+
}, log = (msgs) => {
|
|
18
|
+
msgs.forEach((msg) => {
|
|
19
|
+
console.log(msg);
|
|
20
|
+
});
|
|
21
|
+
}, options = {
|
|
22
|
+
jsxRuntime: "preserve",
|
|
23
|
+
transforms: ["jsx", "typescript"],
|
|
24
|
+
};
|
|
25
|
+
/* -------------------------------------------------------------------------- */
|
|
26
|
+
export default async (filename) => {
|
|
27
|
+
const id = `data-v-${hash(filename)}`, { descriptor, errors } = parse((await (await fetchText(filename)).text()) || "<template></template>"), { script, scriptSetup, slotted, styles, template } = descriptor;
|
|
28
|
+
log(errors);
|
|
25
29
|
const compilerOptions = {
|
|
26
30
|
expressionPlugins: ["jsx", "typescript"],
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (!(
|
|
31
|
-
el = document.createElement("style");
|
|
31
|
+
scopeId: id,
|
|
32
|
+
slotted,
|
|
33
|
+
}, scoped = styles.some(({ scoped }) => scoped), component = scoped ? { __scopeId: id } : {};
|
|
34
|
+
if (!(document.getElementById(id) instanceof HTMLStyleElement)) {
|
|
35
|
+
const el = document.createElement("style"), warnings = new Set();
|
|
32
36
|
el.id = id;
|
|
37
|
+
el.textContent = (await Promise.all(styles.map(async ({ content, module, scoped = false, src }) => {
|
|
38
|
+
const { code, errors } = await compileStyleAsync({
|
|
39
|
+
filename,
|
|
40
|
+
id,
|
|
41
|
+
scoped,
|
|
42
|
+
source: src ? await (await fetchText(src)).text() : content,
|
|
43
|
+
});
|
|
44
|
+
if (module)
|
|
45
|
+
warnings.add("<style module> is not supported in the playground.");
|
|
46
|
+
log(errors);
|
|
47
|
+
return code;
|
|
48
|
+
}))).join("\n");
|
|
33
49
|
document.head.appendChild(el);
|
|
50
|
+
log([...warnings]);
|
|
34
51
|
}
|
|
35
|
-
el.textContent = (await Promise.all(styles.map(async ({ content, module, scoped = false, src }) => {
|
|
36
|
-
const { code, errors } = await compileStyleAsync({
|
|
37
|
-
filename,
|
|
38
|
-
id,
|
|
39
|
-
modules: !!module,
|
|
40
|
-
scoped,
|
|
41
|
-
source: src ? await (await fetchText(src)).text() : content,
|
|
42
|
-
});
|
|
43
|
-
log(errors);
|
|
44
|
-
return code;
|
|
45
|
-
}))).join("\n");
|
|
46
52
|
if (script || scriptSetup) {
|
|
47
53
|
const { bindings, content, warnings = [], } = compileScript(descriptor, { id });
|
|
48
|
-
|
|
49
|
-
if (bindings)
|
|
54
|
+
if (template && bindings)
|
|
50
55
|
compilerOptions.bindingMetadata = bindings;
|
|
51
|
-
Object.assign(
|
|
56
|
+
Object.assign(component, (await inject(transform(content, options).code)).default);
|
|
57
|
+
log(warnings);
|
|
52
58
|
}
|
|
53
59
|
if (template) {
|
|
54
|
-
const { content: source } = template
|
|
55
|
-
|
|
60
|
+
const { ast, content: source } = template, { code, errors, tips } = compileTemplate({
|
|
61
|
+
...(ast && { ast }),
|
|
56
62
|
compilerOptions,
|
|
57
63
|
filename,
|
|
58
64
|
id,
|
|
59
|
-
scoped
|
|
65
|
+
scoped,
|
|
60
66
|
slotted,
|
|
61
67
|
source,
|
|
62
68
|
});
|
|
63
|
-
|
|
69
|
+
Object.assign(component, await inject(transform(code, options).code));
|
|
64
70
|
log(tips);
|
|
65
|
-
|
|
71
|
+
log(errors);
|
|
66
72
|
}
|
|
67
|
-
return
|
|
73
|
+
return component;
|
|
68
74
|
};
|
|
69
|
-
export default loadModule;
|
package/package.json
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"url": "git+https://github.com/vuebro/loader-sfc.git"
|
|
22
22
|
},
|
|
23
23
|
"license": "AGPL-3.0-only",
|
|
24
|
-
"version": "2.0.
|
|
24
|
+
"version": "2.0.3",
|
|
25
25
|
"type": "module",
|
|
26
26
|
"main": "./dist/loader-sfc.js",
|
|
27
27
|
"types": "./dist/loader-sfc.d.ts",
|
|
@@ -31,24 +31,24 @@
|
|
|
31
31
|
"build": "tsc && vite build"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@eslint/js": "^9.
|
|
34
|
+
"@eslint/js": "^9.37.0",
|
|
35
35
|
"@rollup/plugin-terser": "^0.4.4",
|
|
36
36
|
"@types/hash-sum": "^1.0.2",
|
|
37
37
|
"@types/node": "^24.6.2",
|
|
38
|
-
"eslint": "^9.
|
|
38
|
+
"eslint": "^9.37.0",
|
|
39
39
|
"eslint-config-prettier": "^10.1.8",
|
|
40
40
|
"eslint-import-resolver-typescript": "^4.4.4",
|
|
41
41
|
"eslint-plugin-import-x": "^4.16.1",
|
|
42
|
-
"eslint-plugin-perfectionist": "^4.15.
|
|
42
|
+
"eslint-plugin-perfectionist": "^4.15.1",
|
|
43
43
|
"eslint-plugin-prettier": "^5.5.4",
|
|
44
44
|
"jiti": "^2.6.1",
|
|
45
45
|
"typescript": "^5.9.3",
|
|
46
46
|
"typescript-eslint": "^8.45.0",
|
|
47
|
-
"vite": "^7.1.
|
|
47
|
+
"vite": "^7.1.9"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@vue/compiler-sfc": "^3.5.22",
|
|
51
50
|
"hash-sum": "^2.0.0",
|
|
52
|
-
"sucrase": "^3.35.0"
|
|
51
|
+
"sucrase": "^3.35.0",
|
|
52
|
+
"vue": "^3.5.22"
|
|
53
53
|
}
|
|
54
54
|
}
|