@sdata/web-vue-auto-import-resolver 2.4.0 → 2.4.2
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 +6 -0
- package/README.md +3 -10
- package/index.d.ts +9 -10
- package/index.js +14 -41
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
# [2.4.0](https://github.com/liunnn1994/sd-design/compare/v2.3.1...v2.4.0) (2026-06-15)
|
|
2
|
+
|
|
3
|
+
### Features
|
|
4
|
+
|
|
5
|
+
- 🆕 打包 resolver 的时候无需再次 test 了 ([c64efc1](https://github.com/liunnn1994/sd-design/commit/c64efc10268d83604afd91df90dff534e11581c7))
|
|
6
|
+
|
|
1
7
|
# [2.3.0](https://github.com/liunnn1994/sd-design/compare/v2.2.1...v2.3.0) (2026-06-12)
|
|
2
8
|
|
|
3
9
|
### Bug Fixes
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
`@sdata/web-vue-auto-import-resolver` 为 `@sdata/web-vue` 提供 `unplugin-vue-components` 自动导入解析能力,以及 SCSS 别名解析。
|
|
4
4
|
|
|
5
|
-
解析器会在运行时读取已安装的 `@sdata/web-vue`
|
|
5
|
+
解析器会在运行时读取已安装的 `@sdata/web-vue` 发布产物来识别组件导出,因此新增组件后不需要再维护额外的组件映射文件。
|
|
6
6
|
|
|
7
7
|
当前解析器仅面向模板自动导入场景,不支持 SSR。
|
|
8
8
|
|
|
@@ -26,18 +26,12 @@ export default defineConfig({
|
|
|
26
26
|
vue(),
|
|
27
27
|
createSdDesignVitePlugin(),
|
|
28
28
|
Components({
|
|
29
|
-
resolvers: [
|
|
30
|
-
SdDesignResolver({
|
|
31
|
-
sideEffect: true,
|
|
32
|
-
}),
|
|
33
|
-
],
|
|
29
|
+
resolvers: [SdDesignResolver()],
|
|
34
30
|
}),
|
|
35
31
|
],
|
|
36
32
|
});
|
|
37
33
|
```
|
|
38
34
|
|
|
39
|
-
`sideEffect: true` 会自动注入组件样式入口,例如 `@sdata/web-vue/es/button/style/index.js`。
|
|
40
|
-
|
|
41
35
|
`createSdDesignVitePlugin()` 会自动配置 Sass importer 来解析 `@sdata/web-vue` SCSS 文件中的 `@style/` 和 `@components/` 别名。
|
|
42
36
|
|
|
43
37
|
## 手动配置 SCSS importer
|
|
@@ -65,13 +59,12 @@ export default defineConfig({
|
|
|
65
59
|
|
|
66
60
|
```ts
|
|
67
61
|
interface SdDesignResolverOptions {
|
|
62
|
+
/** @default 'Sd' */
|
|
68
63
|
prefix?: string;
|
|
69
|
-
sideEffect?: boolean;
|
|
70
64
|
}
|
|
71
65
|
```
|
|
72
66
|
|
|
73
67
|
- `prefix`:组件前缀,默认是 `Sd`,对应模板里的 `<sd-button />`。
|
|
74
|
-
- `sideEffect`:是否自动导入组件样式。
|
|
75
68
|
|
|
76
69
|
### createSdDesignScssImporter / createSdDesignVitePlugin
|
|
77
70
|
|
package/index.d.ts
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
import * as node_url from 'node:url';
|
|
2
|
-
import {
|
|
2
|
+
import { ComponentResolver } from 'unplugin-vue-components/types';
|
|
3
3
|
import { Plugin } from 'vite';
|
|
4
4
|
|
|
5
|
-
interface SdDesignComponentMeta {
|
|
6
|
-
importName: string;
|
|
7
|
-
from: string;
|
|
8
|
-
sideEffects?: string;
|
|
9
|
-
}
|
|
10
5
|
interface SdDesignResolverOptions {
|
|
6
|
+
/** @default 'Sd' */
|
|
11
7
|
prefix?: string;
|
|
12
|
-
sideEffect?: boolean;
|
|
13
|
-
resolve?: (meta: SdDesignComponentMeta, type: 'component') => ComponentResolveResult | undefined;
|
|
14
8
|
}
|
|
15
9
|
interface SdDesignScssImporterOptions {
|
|
16
10
|
/** @default '@sdata/web-vue' */
|
|
@@ -18,6 +12,11 @@ interface SdDesignScssImporterOptions {
|
|
|
18
12
|
}
|
|
19
13
|
interface SdDesignVitePluginOptions extends SdDesignScssImporterOptions {
|
|
20
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Resolver for SD Design Vue
|
|
17
|
+
*
|
|
18
|
+
* @link https://www.npmjs.com/package/@sdata/web-vue
|
|
19
|
+
*/
|
|
21
20
|
declare function SdDesignResolver(options?: SdDesignResolverOptions): ComponentResolver[];
|
|
22
21
|
/**
|
|
23
22
|
* Create a custom Sass importer that resolves `@style/` and `@components/`
|
|
@@ -62,11 +61,11 @@ declare function createSdDesignScssImporter(options?: SdDesignScssImporterOption
|
|
|
62
61
|
* export default defineConfig({
|
|
63
62
|
* plugins: [
|
|
64
63
|
* createSdDesignVitePlugin(),
|
|
65
|
-
* Components({ resolvers: [SdDesignResolver(
|
|
64
|
+
* Components({ resolvers: [SdDesignResolver()] }),
|
|
66
65
|
* ],
|
|
67
66
|
* });
|
|
68
67
|
* ```
|
|
69
68
|
*/
|
|
70
69
|
declare function createSdDesignVitePlugin(options?: SdDesignVitePluginOptions): Plugin;
|
|
71
70
|
|
|
72
|
-
export {
|
|
71
|
+
export { SdDesignResolver, type SdDesignResolverOptions, type SdDesignScssImporterOptions, type SdDesignVitePluginOptions, createSdDesignScssImporter, createSdDesignVitePlugin };
|
package/index.js
CHANGED
|
@@ -7,16 +7,7 @@ import { fileURLToPath, pathToFileURL } from "url";
|
|
|
7
7
|
var DEFAULT_PREFIX = "Sd";
|
|
8
8
|
var PACKAGE_NAME = "@sdata/web-vue";
|
|
9
9
|
var SASS_EXTENSIONS = [".scss", ".sass", ".css"];
|
|
10
|
-
var
|
|
11
|
-
var getName = (name, prefix) => {
|
|
12
|
-
if (!prefix) {
|
|
13
|
-
return name;
|
|
14
|
-
}
|
|
15
|
-
if (!name.startsWith(prefix)) {
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
return name.substring(prefix.length);
|
|
19
|
-
};
|
|
10
|
+
var cachedComponentSet;
|
|
20
11
|
var parseImportClause = (clause, modulePath, importPathMap) => {
|
|
21
12
|
const trimmedClause = clause.trim();
|
|
22
13
|
if (!trimmedClause) {
|
|
@@ -44,9 +35,9 @@ var getPackageRoot = () => {
|
|
|
44
35
|
const require2 = createRequire(import.meta.url);
|
|
45
36
|
return path.dirname(require2.resolve(`${PACKAGE_NAME}/package.json`));
|
|
46
37
|
};
|
|
47
|
-
var
|
|
48
|
-
if (
|
|
49
|
-
return
|
|
38
|
+
var getComponentExportSet = () => {
|
|
39
|
+
if (cachedComponentSet) {
|
|
40
|
+
return cachedComponentSet;
|
|
50
41
|
}
|
|
51
42
|
const packageRoot = getPackageRoot();
|
|
52
43
|
const entryPath = path.resolve(packageRoot, "es/index.js");
|
|
@@ -62,11 +53,11 @@ var getComponentMetaMap = () => {
|
|
|
62
53
|
}
|
|
63
54
|
const exportBlockMatch = /export\s*\{([\s\S]*?)\};?\s*$/.exec(source);
|
|
64
55
|
if (!exportBlockMatch?.[1]) {
|
|
65
|
-
|
|
66
|
-
return
|
|
56
|
+
cachedComponentSet = /* @__PURE__ */ new Set();
|
|
57
|
+
return cachedComponentSet;
|
|
67
58
|
}
|
|
68
59
|
const exportSpecifiers = exportBlockMatch[1].split(",").map((item) => item.trim()).filter(Boolean);
|
|
69
|
-
const
|
|
60
|
+
const componentSet = /* @__PURE__ */ new Set();
|
|
70
61
|
for (const exportSpecifier of exportSpecifiers) {
|
|
71
62
|
const [localName, exportedName] = exportSpecifier.split(/\s+as\s+/i).map((item) => item.trim());
|
|
72
63
|
const importName = exportedName ?? localName;
|
|
@@ -77,23 +68,10 @@ var getComponentMetaMap = () => {
|
|
|
77
68
|
if (!modulePath || modulePath.startsWith("./_") || modulePath === "./sd-vue.js") {
|
|
78
69
|
continue;
|
|
79
70
|
}
|
|
80
|
-
|
|
81
|
-
const styleFile = path.resolve(packageRoot, "es", styleDir, "style/index.js");
|
|
82
|
-
componentMap[importName] = {
|
|
83
|
-
importName,
|
|
84
|
-
from: PACKAGE_NAME,
|
|
85
|
-
...existsSync(styleFile) ? { sideEffects: `${PACKAGE_NAME}/es/${styleDir}/style/index.js` } : {}
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
cachedComponentMap = componentMap;
|
|
89
|
-
return componentMap;
|
|
90
|
-
};
|
|
91
|
-
var resolveSideEffects = (meta, options) => {
|
|
92
|
-
const shouldIncludeSideEffects = options.sideEffect ?? false;
|
|
93
|
-
if (!shouldIncludeSideEffects || !meta.sideEffects) {
|
|
94
|
-
return;
|
|
71
|
+
componentSet.add(importName);
|
|
95
72
|
}
|
|
96
|
-
|
|
73
|
+
cachedComponentSet = componentSet;
|
|
74
|
+
return componentSet;
|
|
97
75
|
};
|
|
98
76
|
function SdDesignResolver(options = {}) {
|
|
99
77
|
const prefix = options.prefix ?? DEFAULT_PREFIX;
|
|
@@ -101,19 +79,14 @@ function SdDesignResolver(options = {}) {
|
|
|
101
79
|
{
|
|
102
80
|
type: "component",
|
|
103
81
|
resolve: (name) => {
|
|
104
|
-
|
|
105
|
-
if (!componentName) {
|
|
82
|
+
if (!name.startsWith(prefix)) {
|
|
106
83
|
return;
|
|
107
84
|
}
|
|
108
|
-
const
|
|
109
|
-
if (!
|
|
85
|
+
const componentName = name.substring(prefix.length);
|
|
86
|
+
if (!componentName || !getComponentExportSet().has(componentName)) {
|
|
110
87
|
return;
|
|
111
88
|
}
|
|
112
|
-
return
|
|
113
|
-
name: meta.importName,
|
|
114
|
-
from: meta.from,
|
|
115
|
-
sideEffects: resolveSideEffects(meta, options)
|
|
116
|
-
};
|
|
89
|
+
return { name, from: PACKAGE_NAME };
|
|
117
90
|
}
|
|
118
91
|
}
|
|
119
92
|
];
|