@sdata/web-vue-auto-import-resolver 2.2.0 → 2.4.0

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 CHANGED
@@ -1,3 +1,31 @@
1
+ # [2.3.0](https://github.com/liunnn1994/sd-design/compare/v2.2.1...v2.3.0) (2026-06-12)
2
+
3
+ ### Bug Fixes
4
+
5
+ - **anchor:** 将 affix 属性的默认值改为 false ([1b444cb](https://github.com/liunnn1994/sd-design/commit/1b444cb3da97daab4cf450593ab886f18c233764))
6
+ - **date-picker:** 修复日期面板年份边界问题并优化日期计算 ([df04707](https://github.com/liunnn1994/sd-design/commit/df0470752775cb4b8a65ad7698550e03f49ddf7c))
7
+ - **locale:** 修复部分国际化语言检验信息字段缺失问题 ([#3656](https://github.com/liunnn1994/sd-design/issues/3656)) ([8eab41d](https://github.com/liunnn1994/sd-design/commit/8eab41dead8119cc31c7d1558e5c3a6d99892686))
8
+ - **mention:** 清除输入后关闭弹出层并重置测量信息 ([#3653](https://github.com/liunnn1994/sd-design/issues/3653)) ([e7c9aa9](https://github.com/liunnn1994/sd-design/commit/e7c9aa926d4528136c26ad8f9c378d3314fb836e))
9
+ - **scripts:** 修复 dev-component 构建 watcher 报错 ([#3654](https://github.com/liunnn1994/sd-design/issues/3654)) ([b17b75c](https://github.com/liunnn1994/sd-design/commit/b17b75c17e94044c56c8bd3ef8262a287d0e1de2))
10
+ - **textarea:** update value before input event ([#3659](https://github.com/liunnn1994/sd-design/issues/3659)) ([f7ca0c0](https://github.com/liunnn1994/sd-design/commit/f7ca0c0f7899f086de9e93a67f408a53b77b9c0e))
11
+ - **verification-code:** 修复验证码输入框光标定位与聚焦行为 ([#3658](https://github.com/liunnn1994/sd-design/issues/3658)) ([4b36fef](https://github.com/liunnn1994/sd-design/commit/4b36fef9bf54c2485cbf67b064e07793a5991c20))
12
+
13
+ ### Features
14
+
15
+ - **anchor:** 新增横向锚点并优化文档示例 ([8699aee](https://github.com/liunnn1994/sd-design/commit/8699aeee4dacd25138251c5a7f6089533748cac6))
16
+ - **button:** 新增 loadingFixedWidth 和 autoInsertSpaceInButton 属性 ([1ed094f](https://github.com/liunnn1994/sd-design/commit/1ed094fc1102337b47e689d8cf453f48d5aa4f81))
17
+ - **calendar:** 新增卡片模式、下拉头部和日期内容定制功能 ([3b42562](https://github.com/liunnn1994/sd-design/commit/3b425628218dbaf96b66518cedd80345e7d2b016))
18
+ - **date-picker:** 新增 inputProps 与 fixedTime 属性并支持自定义面板头部格式 ([a19694d](https://github.com/liunnn1994/sd-design/commit/a19694d90a6974152287104e7dfa6d1ff2a2896b))
19
+ - **date-picker:** 新增时区支持、隐藏灰色日期和范围重选清空功能 ([b5d912f](https://github.com/liunnn1994/sd-design/commit/b5d912f95b171fa44df77d6f1b144ef2ee56ef9f))
20
+ - **modal:** 新增全局配置和批量关闭功能 ([ff66efd](https://github.com/liunnn1994/sd-design/commit/ff66efd03ea8019e8ef801c31e670c7bad188026))
21
+ - 🆕 去掉自定义的render-function,改为使用官方写法 ([6a865c8](https://github.com/liunnn1994/sd-design/commit/6a865c851a10e560040ea0e4713ddec06e924ff2))
22
+
23
+ # [2.2.0](https://github.com/liunnn1994/sd-design/compare/v2.1.1...v2.2.0) (2026-06-11)
24
+
25
+ ### Features
26
+
27
+ - 🆕 迁移到 composition api ([a719b6f](https://github.com/liunnn1994/sd-design/commit/a719b6f3c065ae0856bbdfde6198f86c15add1a4))
28
+
1
29
  # [2.0.0](https://github.com/liunnn1994/sd-design/compare/v1.20.0...v2.0.0) (2026-06-08)
2
30
 
3
31
  ### Bug Fixes
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @sdata/web-vue-auto-import-resolver
2
2
 
3
- `@sdata/web-vue-auto-import-resolver` 为 `@sdata/web-vue` 提供 `unplugin-vue-components` 自动导入解析能力。
3
+ `@sdata/web-vue-auto-import-resolver` 为 `@sdata/web-vue` 提供 `unplugin-vue-components` 自动导入解析能力,以及 SCSS 别名解析。
4
4
 
5
5
  解析器会在运行时读取已安装的 `@sdata/web-vue` 发布产物来识别组件导出和样式入口,因此新增组件后不需要再维护额外的组件映射文件。
6
6
 
@@ -13,17 +13,18 @@ pnpm add @sdata/web-vue
13
13
  pnpm add -D @sdata/web-vue-auto-import-resolver unplugin-vue-components
14
14
  ```
15
15
 
16
- ## Vite
16
+ ## Vite(推荐)
17
17
 
18
18
  ```ts
19
19
  import { defineConfig } from 'vite';
20
20
  import vue from '@vitejs/plugin-vue';
21
21
  import Components from 'unplugin-vue-components/vite';
22
- import { SdDesignResolver } from '@sdata/web-vue-auto-import-resolver';
22
+ import { SdDesignResolver, createSdDesignVitePlugin } from '@sdata/web-vue-auto-import-resolver';
23
23
 
24
24
  export default defineConfig({
25
25
  plugins: [
26
26
  vue(),
27
+ createSdDesignVitePlugin(),
27
28
  Components({
28
29
  resolvers: [
29
30
  SdDesignResolver({
@@ -37,8 +38,31 @@ export default defineConfig({
37
38
 
38
39
  `sideEffect: true` 会自动注入组件样式入口,例如 `@sdata/web-vue/es/button/style/index.js`。
39
40
 
41
+ `createSdDesignVitePlugin()` 会自动配置 Sass importer 来解析 `@sdata/web-vue` SCSS 文件中的 `@style/` 和 `@components/` 别名。
42
+
43
+ ## 手动配置 SCSS importer
44
+
45
+ `createSdDesignVitePlugin()` 实际上就是在 `config` hook 里调用了 `createSdDesignScssImporter()` 并注入到 `css.preprocessorOptions.scss.importers`。如果你不想用 Vite 插件,或者需要在非 Vite 环境下使用,可以手动配置:
46
+
47
+ ```ts
48
+ import { defineConfig } from 'vite';
49
+ import { createSdDesignScssImporter } from '@sdata/web-vue-auto-import-resolver';
50
+
51
+ export default defineConfig({
52
+ css: {
53
+ preprocessorOptions: {
54
+ scss: {
55
+ importers: [createSdDesignScssImporter()],
56
+ },
57
+ },
58
+ },
59
+ });
60
+ ```
61
+
40
62
  ## 选项
41
63
 
64
+ ### SdDesignResolver
65
+
42
66
  ```ts
43
67
  interface SdDesignResolverOptions {
44
68
  prefix?: string;
@@ -48,3 +72,14 @@ interface SdDesignResolverOptions {
48
72
 
49
73
  - `prefix`:组件前缀,默认是 `Sd`,对应模板里的 `<sd-button />`。
50
74
  - `sideEffect`:是否自动导入组件样式。
75
+
76
+ ### createSdDesignScssImporter / createSdDesignVitePlugin
77
+
78
+ ```ts
79
+ interface SdDesignScssImporterOptions {
80
+ /** @default '@sdata/web-vue' */
81
+ packageName?: string;
82
+ }
83
+ ```
84
+
85
+ - `packageName`:`@sdata/web-vue` 的包名,默认不需要修改。
package/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
+ import * as node_url from 'node:url';
1
2
  import { ComponentResolveResult, ComponentResolver } from 'unplugin-vue-components/types';
3
+ import { Plugin } from 'vite';
2
4
 
3
5
  interface SdDesignComponentMeta {
4
6
  importName: string;
@@ -10,6 +12,61 @@ interface SdDesignResolverOptions {
10
12
  sideEffect?: boolean;
11
13
  resolve?: (meta: SdDesignComponentMeta, type: 'component') => ComponentResolveResult | undefined;
12
14
  }
15
+ interface SdDesignScssImporterOptions {
16
+ /** @default '@sdata/web-vue' */
17
+ packageName?: string;
18
+ }
19
+ interface SdDesignVitePluginOptions extends SdDesignScssImporterOptions {
20
+ }
13
21
  declare function SdDesignResolver(options?: SdDesignResolverOptions): ComponentResolver[];
22
+ /**
23
+ * Create a custom Sass importer that resolves `@style/` and `@components/`
24
+ * aliases used in `@sdata/web-vue` SCSS files.
25
+ *
26
+ * Use this when you need to configure `css.preprocessorOptions.scss.importers`
27
+ * manually instead of using the Vite plugin.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * import { createSdDesignScssImporter } from '@sdata/web-vue-auto-import-resolver';
32
+ *
33
+ * export default defineConfig({
34
+ * css: {
35
+ * preprocessorOptions: {
36
+ * scss: {
37
+ * importers: [createSdDesignScssImporter()],
38
+ * },
39
+ * },
40
+ * },
41
+ * });
42
+ * ```
43
+ */
44
+ declare function createSdDesignScssImporter(options?: SdDesignScssImporterOptions): {
45
+ canonicalize(url: string): node_url.URL | null;
46
+ load(canonicalUrl: URL): Promise<{
47
+ contents: string;
48
+ syntax: "css" | "scss" | "indented";
49
+ sourceMapUrl: URL;
50
+ } | null>;
51
+ };
52
+ /**
53
+ * Create a Vite plugin that automatically configures a custom Sass importer
54
+ * to resolve `@style/` and `@components/` aliases used in `@sdata/web-vue`
55
+ * SCSS files. Equivalent to calling `createSdDesignScssImporter()` and
56
+ * adding it to `css.preprocessorOptions.scss.importers` manually.
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * import { createSdDesignVitePlugin, SdDesignResolver } from '@sdata/web-vue-auto-import-resolver';
61
+ *
62
+ * export default defineConfig({
63
+ * plugins: [
64
+ * createSdDesignVitePlugin(),
65
+ * Components({ resolvers: [SdDesignResolver({ sideEffect: true })] }),
66
+ * ],
67
+ * });
68
+ * ```
69
+ */
70
+ declare function createSdDesignVitePlugin(options?: SdDesignVitePluginOptions): Plugin;
14
71
 
15
- export { type SdDesignComponentMeta, SdDesignResolver, type SdDesignResolverOptions };
72
+ export { type SdDesignComponentMeta, SdDesignResolver, type SdDesignResolverOptions, type SdDesignScssImporterOptions, type SdDesignVitePluginOptions, createSdDesignScssImporter, createSdDesignVitePlugin };
package/index.js CHANGED
@@ -1,9 +1,12 @@
1
1
  // index.ts
2
2
  import { existsSync, readFileSync } from "fs";
3
+ import { readFile } from "fs/promises";
3
4
  import { createRequire } from "module";
4
5
  import path from "path";
6
+ import { fileURLToPath, pathToFileURL } from "url";
5
7
  var DEFAULT_PREFIX = "Sd";
6
8
  var PACKAGE_NAME = "@sdata/web-vue";
9
+ var SASS_EXTENSIONS = [".scss", ".sass", ".css"];
7
10
  var cachedComponentMap;
8
11
  var getName = (name, prefix) => {
9
12
  if (!prefix) {
@@ -115,6 +118,89 @@ function SdDesignResolver(options = {}) {
115
118
  }
116
119
  ];
117
120
  }
121
+ function resolveAliasedPath(url, componentsDir) {
122
+ const normalized = url.replaceAll("\\", "/");
123
+ if (/^(?:sass:|https?:|file:)/.test(normalized)) {
124
+ return null;
125
+ }
126
+ let basePath;
127
+ if (normalized.startsWith("@style/")) {
128
+ basePath = path.resolve(componentsDir, "style", normalized.slice("@style/".length));
129
+ } else if (normalized.startsWith("@components/")) {
130
+ basePath = path.resolve(componentsDir, normalized.slice("@components/".length));
131
+ } else {
132
+ return null;
133
+ }
134
+ const ext = path.extname(basePath);
135
+ const dir = path.dirname(basePath);
136
+ const base = path.basename(basePath);
137
+ const candidates = ext ? [basePath] : [
138
+ ...SASS_EXTENSIONS.map((e) => `${basePath}${e}`),
139
+ ...SASS_EXTENSIONS.map((e) => path.join(dir, `_${base}${e}`)),
140
+ ...SASS_EXTENSIONS.map((e) => path.join(basePath, `index${e}`)),
141
+ ...SASS_EXTENSIONS.map((e) => path.join(basePath, `_index${e}`))
142
+ ];
143
+ return candidates.find((c) => existsSync(c)) ?? null;
144
+ }
145
+ function getComponentsDir(packageName) {
146
+ const packageRoot = path.dirname(createRequire(import.meta.url)(`${packageName}/package.json`));
147
+ return path.resolve(packageRoot, "es");
148
+ }
149
+ function createImporter(componentsDir) {
150
+ return {
151
+ canonicalize(url) {
152
+ const resolved = resolveAliasedPath(url, componentsDir);
153
+ return resolved ? pathToFileURL(resolved) : null;
154
+ },
155
+ async load(canonicalUrl) {
156
+ if (canonicalUrl.protocol !== "file:") {
157
+ return null;
158
+ }
159
+ const filePath = fileURLToPath(canonicalUrl);
160
+ const ext = path.extname(filePath);
161
+ let syntax = "scss";
162
+ if (ext === ".sass") {
163
+ syntax = "indented";
164
+ } else if (ext === ".css") {
165
+ syntax = "css";
166
+ }
167
+ return {
168
+ contents: await readFile(filePath, "utf8"),
169
+ syntax,
170
+ sourceMapUrl: canonicalUrl
171
+ };
172
+ }
173
+ };
174
+ }
175
+ function createSdDesignScssImporter(options = {}) {
176
+ const packageName = options.packageName ?? PACKAGE_NAME;
177
+ return createImporter(getComponentsDir(packageName));
178
+ }
179
+ function createSdDesignVitePlugin(options = {}) {
180
+ const packageName = options.packageName ?? PACKAGE_NAME;
181
+ return {
182
+ name: "sd-design",
183
+ config(config) {
184
+ const importer = createImporter(getComponentsDir(packageName));
185
+ const existingScss = config.css?.preprocessorOptions?.scss ?? {};
186
+ const existingImporters = Array.isArray(existingScss.importers) ? existingScss.importers : [];
187
+ return {
188
+ css: {
189
+ ...config.css,
190
+ preprocessorOptions: {
191
+ ...config.css?.preprocessorOptions,
192
+ scss: {
193
+ ...existingScss,
194
+ importers: [importer, ...existingImporters]
195
+ }
196
+ }
197
+ }
198
+ };
199
+ }
200
+ };
201
+ }
118
202
  export {
119
- SdDesignResolver
203
+ SdDesignResolver,
204
+ createSdDesignScssImporter,
205
+ createSdDesignVitePlugin
120
206
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdata/web-vue-auto-import-resolver",
3
- "version": "2.2.0",
3
+ "version": "2.4.0",
4
4
  "description": "Auto import resolver for @sdata/web-vue and unplugin-vue-components.",
5
5
  "homepage": "https://sd-design.js.org",
6
6
  "bugs": {
@@ -21,7 +21,8 @@
21
21
  "access": "public"
22
22
  },
23
23
  "peerDependencies": {
24
- "@sdata/web-vue": "*"
24
+ "@sdata/web-vue": "*",
25
+ "vite": "*"
25
26
  },
26
27
  "exports": {
27
28
  ".": {