@sky.ui/core 0.0.21 → 0.0.22
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/CHANGELOG.md +20 -20
- package/LICENSE.md +139 -139
- package/README.md +115 -115
- package/auto-import-loader.js +60 -60
- package/dist/custom-elements.json +3052 -3052
- package/dist/sky-badge/sky-badge.js.map +1 -1
- package/package.json +1 -1
package/auto-import-loader.js
CHANGED
|
@@ -1,60 +1,60 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Webpack loader for @sky.ui/core auto-import: scans entry JS (and optional HTML) for <sky-*>
|
|
3
|
-
* and prepends the corresponding import statements. Use only on the entry file.
|
|
4
|
-
*
|
|
5
|
-
* Options: { packageName?: string, entryHtml?: string }
|
|
6
|
-
* @example
|
|
7
|
-
* rules: [{ test: /main\.js$/, use: [{ loader: '@sky.ui/core/auto-import-loader', options: { entryHtml: 'index.html' } }] }]
|
|
8
|
-
*/
|
|
9
|
-
import path from 'node:path';
|
|
10
|
-
import fs from 'node:fs';
|
|
11
|
-
import { pathToFileURL } from 'node:url';
|
|
12
|
-
import { fileURLToPath } from 'node:url';
|
|
13
|
-
|
|
14
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
15
|
-
const TAG_RE = /<(sky-[a-z][a-z0-9]*(?:-[a-z0-9]+)*)|['"`](sky-[a-z][a-z0-9]*(?:-[a-z0-9]+)*)['"`]/gi;
|
|
16
|
-
|
|
17
|
-
function extractUsedTagNames(content, tagNamesSet) {
|
|
18
|
-
const used = new Set();
|
|
19
|
-
let m;
|
|
20
|
-
TAG_RE.lastIndex = 0;
|
|
21
|
-
while ((m = TAG_RE.exec(content)) !== null) {
|
|
22
|
-
const tag = (m[1] || m[2] || '').toLowerCase();
|
|
23
|
-
if (tagNamesSet.has(tag)) used.add(tag);
|
|
24
|
-
}
|
|
25
|
-
return used;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export default async function SkyUIMainAutoImportLoader(source, map, meta) {
|
|
29
|
-
const callback = this.async();
|
|
30
|
-
const options = this.getOptions() || {};
|
|
31
|
-
const packageName = options.packageName ?? '@sky.ui/core';
|
|
32
|
-
const entryHtml = options.entryHtml ?? 'index.html';
|
|
33
|
-
|
|
34
|
-
try {
|
|
35
|
-
const autoImportPath = path.resolve(__dirname, 'auto-import.js');
|
|
36
|
-
const { SKY_UI_TAG_NAMES } = await import(pathToFileURL(autoImportPath).href);
|
|
37
|
-
const tagNamesSet = SKY_UI_TAG_NAMES;
|
|
38
|
-
|
|
39
|
-
let used = extractUsedTagNames(source, tagNamesSet);
|
|
40
|
-
|
|
41
|
-
const htmlPath = path.resolve(this.context, '..', entryHtml);
|
|
42
|
-
if (fs.existsSync(htmlPath)) {
|
|
43
|
-
const html = fs.readFileSync(htmlPath, 'utf-8');
|
|
44
|
-
extractUsedTagNames(html, tagNamesSet).forEach((t) => used.add(t));
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (used.size === 0) {
|
|
48
|
-
return callback(null, source, map, meta);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const imports = [...used]
|
|
52
|
-
.sort()
|
|
53
|
-
.map((tag) => `import '${packageName}/${tag}';`)
|
|
54
|
-
.join('\n');
|
|
55
|
-
const out = `/** Auto-imported by @sky.ui/core (only used components) */\n${imports}\n\n${source}`;
|
|
56
|
-
callback(null, out, map, meta);
|
|
57
|
-
} catch (err) {
|
|
58
|
-
callback(err);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Webpack loader for @sky.ui/core auto-import: scans entry JS (and optional HTML) for <sky-*>
|
|
3
|
+
* and prepends the corresponding import statements. Use only on the entry file.
|
|
4
|
+
*
|
|
5
|
+
* Options: { packageName?: string, entryHtml?: string }
|
|
6
|
+
* @example
|
|
7
|
+
* rules: [{ test: /main\.js$/, use: [{ loader: '@sky.ui/core/auto-import-loader', options: { entryHtml: 'index.html' } }] }]
|
|
8
|
+
*/
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
import fs from 'node:fs';
|
|
11
|
+
import { pathToFileURL } from 'node:url';
|
|
12
|
+
import { fileURLToPath } from 'node:url';
|
|
13
|
+
|
|
14
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
15
|
+
const TAG_RE = /<(sky-[a-z][a-z0-9]*(?:-[a-z0-9]+)*)|['"`](sky-[a-z][a-z0-9]*(?:-[a-z0-9]+)*)['"`]/gi;
|
|
16
|
+
|
|
17
|
+
function extractUsedTagNames(content, tagNamesSet) {
|
|
18
|
+
const used = new Set();
|
|
19
|
+
let m;
|
|
20
|
+
TAG_RE.lastIndex = 0;
|
|
21
|
+
while ((m = TAG_RE.exec(content)) !== null) {
|
|
22
|
+
const tag = (m[1] || m[2] || '').toLowerCase();
|
|
23
|
+
if (tagNamesSet.has(tag)) used.add(tag);
|
|
24
|
+
}
|
|
25
|
+
return used;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export default async function SkyUIMainAutoImportLoader(source, map, meta) {
|
|
29
|
+
const callback = this.async();
|
|
30
|
+
const options = this.getOptions() || {};
|
|
31
|
+
const packageName = options.packageName ?? '@sky.ui/core';
|
|
32
|
+
const entryHtml = options.entryHtml ?? 'index.html';
|
|
33
|
+
|
|
34
|
+
try {
|
|
35
|
+
const autoImportPath = path.resolve(__dirname, 'auto-import.js');
|
|
36
|
+
const { SKY_UI_TAG_NAMES } = await import(pathToFileURL(autoImportPath).href);
|
|
37
|
+
const tagNamesSet = SKY_UI_TAG_NAMES;
|
|
38
|
+
|
|
39
|
+
let used = extractUsedTagNames(source, tagNamesSet);
|
|
40
|
+
|
|
41
|
+
const htmlPath = path.resolve(this.context, '..', entryHtml);
|
|
42
|
+
if (fs.existsSync(htmlPath)) {
|
|
43
|
+
const html = fs.readFileSync(htmlPath, 'utf-8');
|
|
44
|
+
extractUsedTagNames(html, tagNamesSet).forEach((t) => used.add(t));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (used.size === 0) {
|
|
48
|
+
return callback(null, source, map, meta);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const imports = [...used]
|
|
52
|
+
.sort()
|
|
53
|
+
.map((tag) => `import '${packageName}/${tag}';`)
|
|
54
|
+
.join('\n');
|
|
55
|
+
const out = `/** Auto-imported by @sky.ui/core (only used components) */\n${imports}\n\n${source}`;
|
|
56
|
+
callback(null, out, map, meta);
|
|
57
|
+
} catch (err) {
|
|
58
|
+
callback(err);
|
|
59
|
+
}
|
|
60
|
+
}
|