@uni_toolkit/vite-plugin-component-config 0.0.4 → 0.0.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.
- package/README.md +28 -2
- package/dist/index.cjs +9 -24
- package/dist/index.js +7 -22
- package/package.json +11 -2
package/README.md
CHANGED
|
@@ -41,29 +41,55 @@ export default defineConfig({
|
|
|
41
41
|
### 修改 Vue 文件
|
|
42
42
|
|
|
43
43
|
```vue
|
|
44
|
+
// custom-component.vue
|
|
44
45
|
<template>
|
|
45
46
|
<view class="container">
|
|
46
47
|
<text>Hello World</text>
|
|
48
|
+
<test></test>
|
|
47
49
|
</view>
|
|
48
50
|
</template>
|
|
49
51
|
|
|
50
52
|
<script>
|
|
53
|
+
import test from '../sub1/test' // 引入子包中的vue组件
|
|
51
54
|
export default {
|
|
52
|
-
name: 'MyComponent'
|
|
55
|
+
name: 'MyComponent',
|
|
56
|
+
components: {
|
|
57
|
+
test
|
|
58
|
+
}
|
|
53
59
|
}
|
|
54
60
|
</script>
|
|
55
61
|
|
|
62
|
+
// #ifdef MP
|
|
56
63
|
<component-config>
|
|
57
|
-
// 此处必须是标准的 json
|
|
64
|
+
// 此处必须是标准的 json 对象,支持条件编译
|
|
58
65
|
{
|
|
59
66
|
"usingComponents": {
|
|
60
67
|
"custom-button": "/components/custom-button"
|
|
61
68
|
},
|
|
69
|
+
"styleIsolation": "apply-shared",
|
|
62
70
|
"componentPlaceholder": {
|
|
63
71
|
"test": "view",
|
|
64
72
|
}
|
|
65
73
|
}
|
|
66
74
|
</component-config>
|
|
75
|
+
// #endif
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
编译到小程序端生成的 `JSON 文件` 如下所示
|
|
79
|
+
|
|
80
|
+
```json
|
|
81
|
+
// custom-component.json
|
|
82
|
+
{
|
|
83
|
+
"component": true,
|
|
84
|
+
"usingComponents": {
|
|
85
|
+
"test": "../sub1/test",
|
|
86
|
+
"custom-button": "/components/custom-button"
|
|
87
|
+
},
|
|
88
|
+
"styleIsolation": "apply-shared",
|
|
89
|
+
"componentPlaceholder": {
|
|
90
|
+
"test": "view"
|
|
91
|
+
}
|
|
92
|
+
}
|
|
67
93
|
```
|
|
68
94
|
|
|
69
95
|
## 配置选项
|
package/dist/index.cjs
CHANGED
|
@@ -35,8 +35,8 @@ __export(src_exports, {
|
|
|
35
35
|
module.exports = __toCommonJS(src_exports);
|
|
36
36
|
var import_shared = require("@uni_toolkit/shared");
|
|
37
37
|
var import_pluginutils = require("@rollup/pluginutils");
|
|
38
|
-
var
|
|
39
|
-
var
|
|
38
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
39
|
+
var import_node_fs = __toESM(require("fs"), 1);
|
|
40
40
|
var import_uni_cli_shared = require("@dcloudio/uni-cli-shared");
|
|
41
41
|
var import_lodash_es = require("lodash-es");
|
|
42
42
|
function vitePluginComponentConfig(options = {
|
|
@@ -54,43 +54,28 @@ function vitePluginComponentConfig(options = {
|
|
|
54
54
|
if (!(0, import_pluginutils.createFilter)(options.include, options.exclude)(id)) {
|
|
55
55
|
return;
|
|
56
56
|
}
|
|
57
|
-
const matches = code.match(
|
|
58
|
-
/<component-config>([\s\S]*?)<\/component-config>/g
|
|
59
|
-
);
|
|
57
|
+
const matches = code.match(/<component-config>([\s\S]*?)<\/component-config>/g);
|
|
60
58
|
if (!matches) {
|
|
61
59
|
return;
|
|
62
60
|
}
|
|
63
61
|
matches.forEach((match) => {
|
|
64
|
-
const content = match.replace(
|
|
65
|
-
|
|
66
|
-
""
|
|
67
|
-
);
|
|
68
|
-
const componentConfig = (0, import_uni_cli_shared.parseJson)(
|
|
69
|
-
content.toString(),
|
|
70
|
-
true,
|
|
71
|
-
import_path.default.basename(id)
|
|
72
|
-
);
|
|
62
|
+
const content = match.replace(/<component-config>|<\/component-config>/g, "");
|
|
63
|
+
const componentConfig = (0, import_uni_cli_shared.parseJson)(content.toString(), true, import_node_path.default.basename(id));
|
|
73
64
|
map.set((0, import_shared.getOutputJsonPath)(id), componentConfig);
|
|
74
65
|
});
|
|
75
|
-
return code.replace(
|
|
76
|
-
/<component-config>[\s\S]*?<\/component-config>/g,
|
|
77
|
-
""
|
|
78
|
-
);
|
|
66
|
+
return code.replace(/<component-config>[\s\S]*?<\/component-config>/g, "");
|
|
79
67
|
},
|
|
80
68
|
closeBundle() {
|
|
81
69
|
if (map.size === 0) {
|
|
82
70
|
return;
|
|
83
71
|
}
|
|
84
72
|
for (const [outputPath, config] of map) {
|
|
85
|
-
if (!
|
|
73
|
+
if (!import_node_fs.default.existsSync(outputPath)) {
|
|
86
74
|
continue;
|
|
87
75
|
}
|
|
88
|
-
const content =
|
|
76
|
+
const content = import_node_fs.default.readFileSync(outputPath, "utf-8");
|
|
89
77
|
const json = JSON.parse(content);
|
|
90
|
-
|
|
91
|
-
outputPath,
|
|
92
|
-
JSON.stringify((0, import_lodash_es.merge)(json, config), null, 2)
|
|
93
|
-
);
|
|
78
|
+
import_node_fs.default.writeFileSync(outputPath, JSON.stringify((0, import_lodash_es.merge)(json, config), null, 2));
|
|
94
79
|
}
|
|
95
80
|
}
|
|
96
81
|
};
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import { getOutputJsonPath, isMiniProgram } from "@uni_toolkit/shared";
|
|
3
3
|
import { createFilter } from "@rollup/pluginutils";
|
|
4
|
-
import path from "path";
|
|
5
|
-
import fs from "fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import fs from "node:fs";
|
|
6
6
|
import { parseJson } from "@dcloudio/uni-cli-shared";
|
|
7
7
|
import { merge } from "lodash-es";
|
|
8
8
|
function vitePluginComponentConfig(options = {
|
|
@@ -20,28 +20,16 @@ function vitePluginComponentConfig(options = {
|
|
|
20
20
|
if (!createFilter(options.include, options.exclude)(id)) {
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
|
-
const matches = code.match(
|
|
24
|
-
/<component-config>([\s\S]*?)<\/component-config>/g
|
|
25
|
-
);
|
|
23
|
+
const matches = code.match(/<component-config>([\s\S]*?)<\/component-config>/g);
|
|
26
24
|
if (!matches) {
|
|
27
25
|
return;
|
|
28
26
|
}
|
|
29
27
|
matches.forEach((match) => {
|
|
30
|
-
const content = match.replace(
|
|
31
|
-
|
|
32
|
-
""
|
|
33
|
-
);
|
|
34
|
-
const componentConfig = parseJson(
|
|
35
|
-
content.toString(),
|
|
36
|
-
true,
|
|
37
|
-
path.basename(id)
|
|
38
|
-
);
|
|
28
|
+
const content = match.replace(/<component-config>|<\/component-config>/g, "");
|
|
29
|
+
const componentConfig = parseJson(content.toString(), true, path.basename(id));
|
|
39
30
|
map.set(getOutputJsonPath(id), componentConfig);
|
|
40
31
|
});
|
|
41
|
-
return code.replace(
|
|
42
|
-
/<component-config>[\s\S]*?<\/component-config>/g,
|
|
43
|
-
""
|
|
44
|
-
);
|
|
32
|
+
return code.replace(/<component-config>[\s\S]*?<\/component-config>/g, "");
|
|
45
33
|
},
|
|
46
34
|
closeBundle() {
|
|
47
35
|
if (map.size === 0) {
|
|
@@ -53,10 +41,7 @@ function vitePluginComponentConfig(options = {
|
|
|
53
41
|
}
|
|
54
42
|
const content = fs.readFileSync(outputPath, "utf-8");
|
|
55
43
|
const json = JSON.parse(content);
|
|
56
|
-
fs.writeFileSync(
|
|
57
|
-
outputPath,
|
|
58
|
-
JSON.stringify(merge(json, config), null, 2)
|
|
59
|
-
);
|
|
44
|
+
fs.writeFileSync(outputPath, JSON.stringify(merge(json, config), null, 2));
|
|
60
45
|
}
|
|
61
46
|
}
|
|
62
47
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uni_toolkit/vite-plugin-component-config",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "chouchouji <1305974212@qq.com>",
|
|
6
6
|
"type": "module",
|
|
@@ -11,6 +11,15 @@
|
|
|
11
11
|
"require": "./dist/index.cjs"
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"uni-app",
|
|
16
|
+
"vue3",
|
|
17
|
+
"miniprogram",
|
|
18
|
+
"vite",
|
|
19
|
+
"plugin",
|
|
20
|
+
"component",
|
|
21
|
+
"custom"
|
|
22
|
+
],
|
|
14
23
|
"publishConfig": {
|
|
15
24
|
"access": "public"
|
|
16
25
|
},
|
|
@@ -32,7 +41,7 @@
|
|
|
32
41
|
"vite": "^7.1.7",
|
|
33
42
|
"@rollup/pluginutils": "^5.3.0",
|
|
34
43
|
"lodash-es": "^4.17.21",
|
|
35
|
-
"@uni_toolkit/shared": "0.0.
|
|
44
|
+
"@uni_toolkit/shared": "0.0.6"
|
|
36
45
|
},
|
|
37
46
|
"devDependencies": {
|
|
38
47
|
"typescript": "5.3.3",
|