@vuebro/loader-sfc 2.3.5 → 2.3.7
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.js +0 -42
- package/package.json +9 -31
package/dist/loader-sfc.js
CHANGED
|
@@ -2,9 +2,6 @@ import { consola } from "consola/browser";
|
|
|
2
2
|
import hash from "hash-sum";
|
|
3
3
|
import { transform } from "sucrase";
|
|
4
4
|
import { compileScript, compileStyleAsync, compileTemplate, parse, } from "vue/compiler-sfc";
|
|
5
|
-
/* -------------------------------------------------------------------------- */
|
|
6
|
-
/* Служебные функции */
|
|
7
|
-
/* -------------------------------------------------------------------------- */
|
|
8
5
|
const fetchText = async (url) => {
|
|
9
6
|
try {
|
|
10
7
|
const response = await fetch(url);
|
|
@@ -22,21 +19,9 @@ const fetchText = async (url) => {
|
|
|
22
19
|
URL.revokeObjectURL(objectURL);
|
|
23
20
|
}
|
|
24
21
|
};
|
|
25
|
-
/* -------------------------------------------------------------------------- */
|
|
26
|
-
/* Функция загрузки файла с компонентом Vue */
|
|
27
|
-
/* -------------------------------------------------------------------------- */
|
|
28
22
|
export default async (filename, { parseOptions, scriptOptions: { templateOptions: { compilerOptions: { expressionPlugins, ...restCompilerOptions } = {}, ...restTemplateOptions } = {}, ...restScriptOptions } = {}, styleOptions, } = {}) => {
|
|
29
|
-
/* -------------------------------------------------------------------------- */
|
|
30
|
-
/* Генерация уникального идентификатора */
|
|
31
|
-
/* -------------------------------------------------------------------------- */
|
|
32
23
|
const id = `data-v-${hash(filename)}`;
|
|
33
|
-
/* -------------------------------------------------------------------------- */
|
|
34
|
-
/* Загрузка и парсинг файла с компонентом Vue */
|
|
35
|
-
/* -------------------------------------------------------------------------- */
|
|
36
24
|
const { descriptor, errors: parseErrors } = parse((await (await fetchText(filename)).text()) || "<template></template>", { filename, ...parseOptions });
|
|
37
|
-
/* -------------------------------------------------------------------------- */
|
|
38
|
-
/* Обработка полученных данных */
|
|
39
|
-
/* -------------------------------------------------------------------------- */
|
|
40
25
|
const { script, scriptSetup, slotted, styles, template } = descriptor;
|
|
41
26
|
const langs = new Set([script, scriptSetup]
|
|
42
27
|
.filter((scriptBlock) => scriptBlock !== null)
|
|
@@ -44,9 +29,6 @@ export default async (filename, { parseOptions, scriptOptions: { templateOptions
|
|
|
44
29
|
...(/[jt]sx$/.test(lang) ? ["jsx"] : []),
|
|
45
30
|
...(/tsx?$/.test(lang) ? ["typescript"] : []),
|
|
46
31
|
])), { ast, content: source = "" } = template ?? {};
|
|
47
|
-
/* -------------------------------------------------------------------------- */
|
|
48
|
-
/* Загрузка и компилирование стилей */
|
|
49
|
-
/* -------------------------------------------------------------------------- */
|
|
50
32
|
let styleWarning = "";
|
|
51
33
|
const styleErrors = [];
|
|
52
34
|
const style = !(document.getElementById(id) instanceof HTMLStyleElement)
|
|
@@ -70,9 +52,6 @@ export default async (filename, { parseOptions, scriptOptions: { templateOptions
|
|
|
70
52
|
}
|
|
71
53
|
}))
|
|
72
54
|
: Promise.resolve([]);
|
|
73
|
-
/* -------------------------------------------------------------------------- */
|
|
74
|
-
/* Подготовка настроек */
|
|
75
|
-
/* -------------------------------------------------------------------------- */
|
|
76
55
|
const compilerOptions = {
|
|
77
56
|
expressionPlugins: [
|
|
78
57
|
...new Set([...(expressionPlugins ?? []), ...langs]),
|
|
@@ -96,18 +75,9 @@ export default async (filename, { parseOptions, scriptOptions: { templateOptions
|
|
|
96
75
|
jsxRuntime: "preserve",
|
|
97
76
|
transforms: [...langs],
|
|
98
77
|
};
|
|
99
|
-
/* -------------------------------------------------------------------------- */
|
|
100
|
-
/* Компиляция скрипта */
|
|
101
|
-
/* -------------------------------------------------------------------------- */
|
|
102
78
|
const { bindings, content, warnings: scriptWarnings, } = script || scriptSetup ? compileScript(descriptor, scriptOptions) : {};
|
|
103
|
-
/* -------------------------------------------------------------------------- */
|
|
104
|
-
/* Связывание метаданных */
|
|
105
|
-
/* -------------------------------------------------------------------------- */
|
|
106
79
|
if (bindings)
|
|
107
80
|
compilerOptions.bindingMetadata = bindings;
|
|
108
|
-
/* -------------------------------------------------------------------------- */
|
|
109
|
-
/* Компиляция шаблона */
|
|
110
|
-
/* -------------------------------------------------------------------------- */
|
|
111
81
|
const { code, errors: templateErrors, tips: templateTips, } = template && (!scriptSetup || !scriptOptions.inlineTemplate)
|
|
112
82
|
? compileTemplate({
|
|
113
83
|
...ast,
|
|
@@ -117,9 +87,6 @@ export default async (filename, { parseOptions, scriptOptions: { templateOptions
|
|
|
117
87
|
...templateOptions,
|
|
118
88
|
})
|
|
119
89
|
: {};
|
|
120
|
-
/* -------------------------------------------------------------------------- */
|
|
121
|
-
/* Вывод ошибок, предупреждений и подсказок */
|
|
122
|
-
/* -------------------------------------------------------------------------- */
|
|
123
90
|
[...parseErrors, ...(templateErrors ?? []), ...styleErrors].forEach((error) => {
|
|
124
91
|
consola.error(error);
|
|
125
92
|
});
|
|
@@ -129,9 +96,6 @@ export default async (filename, { parseOptions, scriptOptions: { templateOptions
|
|
|
129
96
|
[...(templateTips ?? [])].forEach((info) => {
|
|
130
97
|
consola.info(info);
|
|
131
98
|
});
|
|
132
|
-
/* -------------------------------------------------------------------------- */
|
|
133
|
-
/* Получение и обработка результатов */
|
|
134
|
-
/* -------------------------------------------------------------------------- */
|
|
135
99
|
const [styleResult, scriptResult, templateResult] = await Promise.all([
|
|
136
100
|
style,
|
|
137
101
|
content
|
|
@@ -141,9 +105,6 @@ export default async (filename, { parseOptions, scriptOptions: { templateOptions
|
|
|
141
105
|
? inject(langs.size ? transform(code, sucraseOptions).code : code)
|
|
142
106
|
: Promise.resolve(undefined),
|
|
143
107
|
]);
|
|
144
|
-
/* -------------------------------------------------------------------------- */
|
|
145
|
-
/* Внедрение стилей в документ */
|
|
146
|
-
/* -------------------------------------------------------------------------- */
|
|
147
108
|
const textContent = styleResult.join("\n").trim();
|
|
148
109
|
if (textContent) {
|
|
149
110
|
const el = document.createElement("style");
|
|
@@ -151,8 +112,5 @@ export default async (filename, { parseOptions, scriptOptions: { templateOptions
|
|
|
151
112
|
el.textContent = textContent;
|
|
152
113
|
document.head.appendChild(el);
|
|
153
114
|
}
|
|
154
|
-
/* -------------------------------------------------------------------------- */
|
|
155
|
-
/* Формирование возвращаемого компонента */
|
|
156
|
-
/* -------------------------------------------------------------------------- */
|
|
157
115
|
return { __scopeId: id, ...scriptResult?.["default"], ...templateResult };
|
|
158
116
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vuebro/loader-sfc",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.7",
|
|
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",
|
|
@@ -25,47 +25,25 @@
|
|
|
25
25
|
"type": "module",
|
|
26
26
|
"main": "./dist/loader-sfc.js",
|
|
27
27
|
"types": "./dist/loader-sfc.d.ts",
|
|
28
|
+
"files": [
|
|
29
|
+
"dist"
|
|
30
|
+
],
|
|
28
31
|
"scripts": {
|
|
29
|
-
"build": "
|
|
32
|
+
"build": "tsc && vite build",
|
|
30
33
|
"lint": "eslint ."
|
|
31
34
|
},
|
|
32
35
|
"dependencies": {
|
|
33
|
-
"@types/hash-sum": "^1.0.2",
|
|
34
36
|
"consola": "^3.4.2",
|
|
35
37
|
"hash-sum": "^2.0.0",
|
|
36
38
|
"sucrase": "^3.35.0",
|
|
37
39
|
"vue": "^3.5.22"
|
|
38
40
|
},
|
|
39
41
|
"devDependencies": {
|
|
40
|
-
"@eslint/js": "^9.38.0",
|
|
41
|
-
"@eslint/json": "^0.13.2",
|
|
42
|
-
"@eslint/markdown": "^7.4.0",
|
|
43
|
-
"@prettier/plugin-pug": "^3.4.2",
|
|
44
42
|
"@rollup/plugin-terser": "^0.4.4",
|
|
45
|
-
"@
|
|
43
|
+
"@types/hash-sum": "^1.0.2",
|
|
46
44
|
"@types/node": "^24.8.1",
|
|
47
|
-
"@
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"@vue/tsconfig": "^0.8.1",
|
|
51
|
-
"eslint-config-flat-gitignore": "^2.1.0",
|
|
52
|
-
"eslint-config-prettier": "^10.1.8",
|
|
53
|
-
"eslint-import-resolver-typescript": "^4.4.4",
|
|
54
|
-
"eslint-plugin-de-morgan": "^2.0.0",
|
|
55
|
-
"eslint-plugin-depend": "^1.3.1",
|
|
56
|
-
"eslint-plugin-import-x": "^4.16.1",
|
|
57
|
-
"eslint-plugin-jsdoc": "^61.1.4",
|
|
58
|
-
"eslint-plugin-package-json": "^0.57.0",
|
|
59
|
-
"eslint-plugin-perfectionist": "^4.15.1",
|
|
60
|
-
"eslint-plugin-prettier": "^5.5.4",
|
|
61
|
-
"eslint-plugin-regexp": "^2.10.0",
|
|
62
|
-
"eslint-plugin-vue": "^10.5.1",
|
|
63
|
-
"jiti": "^2.6.1",
|
|
64
|
-
"prettier-plugin-packagejson": "^2.5.19",
|
|
65
|
-
"prettier-plugin-tailwindcss": "^0.7.1",
|
|
66
|
-
"tsc-alias": "^1.8.16",
|
|
67
|
-
"vite": "^7.1.10",
|
|
68
|
-
"vite-plugin-static-copy": "^3.1.4",
|
|
69
|
-
"vue-tsc": "^3.1.1"
|
|
45
|
+
"@vuebro/configs": "^1.1.7",
|
|
46
|
+
"eslint": "^9.38.0",
|
|
47
|
+
"vite": "^7.1.11"
|
|
70
48
|
}
|
|
71
49
|
}
|