@uni_toolkit/vite-plugin-component-config 0.0.1-alpha.1760173856418
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/LICENSE +21 -0
- package/dist/index.cjs +96 -0
- package/dist/index.d.cts +10 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +65 -0
- package/package.json +35 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 chouchouji
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
default: () => vitePluginComponentConfig
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(src_exports);
|
|
36
|
+
var import_shared = require("@uni_toolkit/shared");
|
|
37
|
+
var import_pluginutils = require("@rollup/pluginutils");
|
|
38
|
+
var import_path = __toESM(require("path"), 1);
|
|
39
|
+
var import_fs = __toESM(require("fs"), 1);
|
|
40
|
+
var import_uni_cli_shared = require("@dcloudio/uni-cli-shared");
|
|
41
|
+
function vitePluginComponentConfig(options = {
|
|
42
|
+
include: ["**/*.{vue,nvue,uvue}"],
|
|
43
|
+
exclude: []
|
|
44
|
+
}) {
|
|
45
|
+
const map = /* @__PURE__ */ new Map();
|
|
46
|
+
return {
|
|
47
|
+
name: "vite-plugin-component-config",
|
|
48
|
+
enforce: "pre",
|
|
49
|
+
transform(code, id) {
|
|
50
|
+
if (!import_shared.isMiniProgram) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (!(0, import_pluginutils.createFilter)(options.include, options.exclude)(id)) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const matches = code.match(
|
|
57
|
+
/<component-config>([\s\S]*?)<\/component-config>/g
|
|
58
|
+
);
|
|
59
|
+
if (!matches) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
matches.forEach((match) => {
|
|
63
|
+
const content = match.replace(
|
|
64
|
+
/<component-config>|<\/component-config>/g,
|
|
65
|
+
""
|
|
66
|
+
);
|
|
67
|
+
const componentConfig = (0, import_uni_cli_shared.parseJson)(
|
|
68
|
+
content.toString(),
|
|
69
|
+
true,
|
|
70
|
+
import_path.default.basename(id)
|
|
71
|
+
);
|
|
72
|
+
map.set((0, import_shared.getOutputJsonPath)(id), componentConfig);
|
|
73
|
+
});
|
|
74
|
+
return code.replace(
|
|
75
|
+
/<component-config>[\s\S]*?<\/component-config>/g,
|
|
76
|
+
""
|
|
77
|
+
);
|
|
78
|
+
},
|
|
79
|
+
closeBundle() {
|
|
80
|
+
if (map.size === 0) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
for (const [outputPath, config] of map) {
|
|
84
|
+
if (!import_fs.default.existsSync(outputPath)) {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
const content = import_fs.default.readFileSync(outputPath, "utf-8");
|
|
88
|
+
const json = JSON.parse(content);
|
|
89
|
+
import_fs.default.writeFileSync(
|
|
90
|
+
outputPath,
|
|
91
|
+
JSON.stringify(Object.assign({}, json, config), null, 2)
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { PluginOption } from 'vite';
|
|
2
|
+
import { FilterPattern } from '@rollup/pluginutils';
|
|
3
|
+
|
|
4
|
+
interface ComponentConfigPluginOptions {
|
|
5
|
+
include?: FilterPattern;
|
|
6
|
+
exclude?: FilterPattern;
|
|
7
|
+
}
|
|
8
|
+
declare function vitePluginComponentConfig(options?: ComponentConfigPluginOptions): PluginOption;
|
|
9
|
+
|
|
10
|
+
export { ComponentConfigPluginOptions, vitePluginComponentConfig as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { PluginOption } from 'vite';
|
|
2
|
+
import { FilterPattern } from '@rollup/pluginutils';
|
|
3
|
+
|
|
4
|
+
interface ComponentConfigPluginOptions {
|
|
5
|
+
include?: FilterPattern;
|
|
6
|
+
exclude?: FilterPattern;
|
|
7
|
+
}
|
|
8
|
+
declare function vitePluginComponentConfig(options?: ComponentConfigPluginOptions): PluginOption;
|
|
9
|
+
|
|
10
|
+
export { ComponentConfigPluginOptions, vitePluginComponentConfig as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { getOutputJsonPath, isMiniProgram } from "@uni_toolkit/shared";
|
|
3
|
+
import { createFilter } from "@rollup/pluginutils";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import fs from "fs";
|
|
6
|
+
import { parseJson } from "@dcloudio/uni-cli-shared";
|
|
7
|
+
function vitePluginComponentConfig(options = {
|
|
8
|
+
include: ["**/*.{vue,nvue,uvue}"],
|
|
9
|
+
exclude: []
|
|
10
|
+
}) {
|
|
11
|
+
const map = /* @__PURE__ */ new Map();
|
|
12
|
+
return {
|
|
13
|
+
name: "vite-plugin-component-config",
|
|
14
|
+
enforce: "pre",
|
|
15
|
+
transform(code, id) {
|
|
16
|
+
if (!isMiniProgram) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (!createFilter(options.include, options.exclude)(id)) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const matches = code.match(
|
|
23
|
+
/<component-config>([\s\S]*?)<\/component-config>/g
|
|
24
|
+
);
|
|
25
|
+
if (!matches) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
matches.forEach((match) => {
|
|
29
|
+
const content = match.replace(
|
|
30
|
+
/<component-config>|<\/component-config>/g,
|
|
31
|
+
""
|
|
32
|
+
);
|
|
33
|
+
const componentConfig = parseJson(
|
|
34
|
+
content.toString(),
|
|
35
|
+
true,
|
|
36
|
+
path.basename(id)
|
|
37
|
+
);
|
|
38
|
+
map.set(getOutputJsonPath(id), componentConfig);
|
|
39
|
+
});
|
|
40
|
+
return code.replace(
|
|
41
|
+
/<component-config>[\s\S]*?<\/component-config>/g,
|
|
42
|
+
""
|
|
43
|
+
);
|
|
44
|
+
},
|
|
45
|
+
closeBundle() {
|
|
46
|
+
if (map.size === 0) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
for (const [outputPath, config] of map) {
|
|
50
|
+
if (!fs.existsSync(outputPath)) {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
const content = fs.readFileSync(outputPath, "utf-8");
|
|
54
|
+
const json = JSON.parse(content);
|
|
55
|
+
fs.writeFileSync(
|
|
56
|
+
outputPath,
|
|
57
|
+
JSON.stringify(Object.assign({}, json, config), null, 2)
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
export {
|
|
64
|
+
vitePluginComponentConfig as default
|
|
65
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@uni_toolkit/vite-plugin-component-config",
|
|
3
|
+
"version": "0.0.1-alpha.1760173856418",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"author": "chouchouji <1305974212@qq.com>",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"require": "./dist/index.cjs"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"main": "dist/index.cjs",
|
|
15
|
+
"module": "dist/index.js",
|
|
16
|
+
"types": "dist/index.d.ts",
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@dcloudio/uni-cli-shared": "3.0.0-alpha-4080120250820001",
|
|
22
|
+
"vite": "^7.1.7",
|
|
23
|
+
"@rollup/pluginutils": "^5.3.0",
|
|
24
|
+
"@uni_toolkit/shared": "0.0.1-alpha.1760173856418"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"typescript": "5.3.3",
|
|
28
|
+
"tsup": "7.2.0",
|
|
29
|
+
"@types/node": "^18.7.20"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsup src/index.ts --format esm,cjs --out-dir=dist --dts --clean",
|
|
33
|
+
"dev": "tsup src/index.ts --format esm --out-dir=dist --watch --dts"
|
|
34
|
+
}
|
|
35
|
+
}
|