@ws-ui/vite-plugins 1.7.4 → 1.7.6

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.
@@ -0,0 +1,11 @@
1
+ import { PluginOption } from 'vite';
2
+ type Rule = {
3
+ target: string;
4
+ keep: RegExp[];
5
+ };
6
+ type ExcludeConfig = {
7
+ exclude: string[];
8
+ rules: Rule[];
9
+ };
10
+ export default function excludeFilesPlugin(config: ExcludeConfig): PluginOption;
11
+ export {};
@@ -0,0 +1,36 @@
1
+ import { rmSync, readdirSync, statSync, existsSync } from 'node:fs';
2
+ import path from 'node:path';
3
+ export default function excludeFilesPlugin(config) {
4
+ return {
5
+ name: 'exclude-files',
6
+ closeBundle() {
7
+ const out = process.env.VITE_BUILD_TARGET || '';
8
+ const baseDir = path.join(process.cwd(), out);
9
+ // Remove exclude files/folders outside of all rule targets
10
+ const ruleTargets = config.rules.map((r) => r.target.replace(/\/$/, ''));
11
+ for (const name of readdirSync(baseDir)) {
12
+ if (ruleTargets.includes(name))
13
+ continue; // skip target folders
14
+ if (config.exclude.includes(name)) {
15
+ rmSync(path.join(baseDir, name), { recursive: true, force: true });
16
+ }
17
+ }
18
+ // Apply each rule: inside target folder, keep matching files, delete others
19
+ for (const rule of config.rules) {
20
+ const targetDir = path.join(baseDir, rule.target);
21
+ if (!existsSync(targetDir))
22
+ continue;
23
+ for (const file of readdirSync(targetDir)) {
24
+ const fp = path.join(targetDir, file);
25
+ if (statSync(fp).isDirectory()) {
26
+ rmSync(fp, { recursive: true, force: true });
27
+ continue;
28
+ }
29
+ const keep = rule.keep.some((re) => re.test(file));
30
+ if (!keep)
31
+ rmSync(fp, { force: true });
32
+ }
33
+ }
34
+ },
35
+ };
36
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ws-ui/vite-plugins",
3
- "version": "1.7.4",
3
+ "version": "1.7.6",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",