Skip to content

Commit 34fb87a

Browse files
author
Night Knight
committed
support Component
1 parent 19673a5 commit 34fb87a

14 files changed

Lines changed: 59 additions & 3 deletions

File tree

.eslintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"__DEV__": true,
6161
"App": true,
6262
"Page": true,
63+
"Component": true,
6364
"wx": true,
6465
"getApp": true,
6566
},

src/index.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,24 @@ export default class WXAppPlugin {
143143
async getEntryResource() {
144144
const appJSONFile = resolve(this.base, 'app.json');
145145
const { pages = [] } = await readJson(appJSONFile);
146-
return ['app'].concat(pages);
146+
const components = new Set();
147+
for (const page of pages) {
148+
await this.getComponents(components, resolve(this.base, page));
149+
}
150+
return ['app', ...pages, ...components];
151+
}
152+
153+
async getComponents(components, instance) {
154+
const { usingComponents = {} } =
155+
await readJson(`${instance}.json`).catch(::console.error);
156+
const componentBase = parse(instance).dir;
157+
for (const relativeComponent of Object.values(usingComponents)) {
158+
const component = resolve(componentBase, relativeComponent);
159+
if (!components.has(component)) {
160+
components.add(relative(this.base, component));
161+
await this.getComponents(components, component);
162+
}
163+
}
147164
}
148165

149166
getFullScriptPath(path) {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Component({})
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"component": true
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<view class="common-text">Common Component loaded.</view>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.common-text {
2+
color: grey;
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Component({})
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"component": true,
3+
"usingComponents": {
4+
"common-component": "../common-component/common-component"
5+
}
6+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<view>
2+
<view>'Index Component loaded.'</view>
3+
<common-component></common-component>
4+
</view>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Component({})

0 commit comments

Comments
 (0)