Skip to content

Commit b819b27

Browse files
authored
Merge pull request #1014 from raxjs/feat/pha_qyy
feat: support html template for tabbar
2 parents 4dc4e63 + 4ecab07 commit b819b27

File tree

5 files changed

+51
-12
lines changed

5 files changed

+51
-12
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
runs-on: ubuntu-latest
88
strategy:
99
matrix:
10-
node-version: [12.x]
10+
node-version: [14.x]
1111
steps:
1212
- uses: actions/checkout@v2
1313
- name: Set branch name

__tests__/build-cases/with-rax-pha.test.ts

+31-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ buildFixture(example, true);
88

99
describe('should build manifest.json: ', () => {
1010
test('manifest.json content', async () => {
11+
1112
const manifestJSON = fs.readJSONSync(path.join(process.cwd(), 'examples', example, 'build/web/manifest.json'));
13+
1214
expect(manifestJSON).toEqual({
1315
app_worker: { url: 'pha-worker.js' },
1416
links: [],
@@ -31,7 +33,35 @@ describe('should build manifest.json: ', () => {
3133
scripts: [
3234
'<script src="https://g.alicdn.com/mtb/lib-promise/3.1.3/polyfillB.js" crossorigin="anonymous" ></script>',
3335
],
34-
tab_bar: { custom: true, list: ['home', 'about-single'], source: '/components/CustomTabBar/index' },
36+
tab_bar: {
37+
custom: true,
38+
list: ['home', 'about-single'],
39+
source: '/components/CustomTabBar/index',
40+
html: '\n' +
41+
' <!DOCTYPE html>\n' +
42+
' <html>\n' +
43+
' <head>\n' +
44+
' <meta charset="utf-8" />\n' +
45+
' \n' +
46+
' <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no,viewport-fit=cover" />\n' +
47+
' <meta name="release-info" content="version=12,app-id=123" />\n' +
48+
'\n' +
49+
' <title>PHA Demo</title>\n' +
50+
' \n' +
51+
' <link rel="stylesheet" href="/customtabbar.css" />\n' +
52+
'\n' +
53+
' </head>\n' +
54+
' <body >\n' +
55+
' \n' +
56+
' <div id="root"></div>\n' +
57+
' <script src="https://g.alicdn.com/mtb/lib-promise/3.1.3/polyfillB.js" crossorigin="anonymous" ></script>\n' +
58+
'\n' +
59+
' \n' +
60+
' <script crossorigin="anonymous" type="application/javascript" src="/customtabbar.js"></script>\n' +
61+
'\n' +
62+
' </body>\n' +
63+
' </html>\n'
64+
},
3565
title: 'PHA Demo',
3666
});
3767
});

packages/plugin-rax-pha/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "build-plugin-rax-pha",
3-
"version": "2.1.3",
3+
"version": "2.1.4",
44
"description": "Rax PHA plugins",
55
"license": "BSD-3-Clause",
66
"main": "lib/index.js",
@@ -20,4 +20,4 @@
2020
"devDependencies": {
2121
"webpack": ">=4.0.0"
2222
}
23-
}
23+
}

packages/plugin-rax-pha/src/manifestHelpers.js

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ function transformAppConfig(appConfig, isRoot = true, parentKey) {
6060
data[transformKey] = value;
6161
}
6262
}
63+
6364
return data;
6465
}
6566

packages/plugin-rax-pha/src/plugins/AppToManifestPlugin.js

+16-8
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ module.exports = class {
4444
}, ({ compilation, callback, assets }) => {
4545
const assetNames = Object.keys(assets);
4646
const appConfig = getValue('staticConfig');
47+
4748
const { scripts, metas, links } = applyMethod('rax.getInjectedHTML');
4849
let manifestJSON = transformAppConfig(appConfig);
4950
const devUrls = [];
@@ -72,8 +73,14 @@ module.exports = class {
7273
manifestJSON.scripts,
7374
) || [];
7475

75-
// if has tabBar, do not generate multiple manifest.json
7676
if (manifestJSON.tab_bar) {
77+
// Try save html string of custom tabbar to html of tab_bar.
78+
const { document } = applyMethod('rax.getDocument', { name: 'customtabbar' }) || {};
79+
if (document && !manifestJSON.html) {
80+
manifestJSON.tab_bar.html = document;
81+
}
82+
83+
// If has tabBar, do not generate multiple manifest.json
7784
manifestJSON = setRealUrlToManifest(
7885
{
7986
urlPrefix: pagePrefix,
@@ -104,14 +111,15 @@ module.exports = class {
104111
})
105112
.forEach(({ source, entryName, __frameIndex }) => {
106113
let copyManifestJSON = cloneDeep(manifestJSON);
107-
copyManifestJSON.pages = copyManifestJSON.pages.filter((page) => {
108-
// has frames
109-
if (__frameIndex === 0) {
110-
return !!(page.frames && page.frames[0] && page.frames[0].source === source);
111-
} else {
112-
return page.source === source;
114+
115+
// Move current page to pages[0].
116+
for (let i = 0; i < copyManifestJSON.pages.length; i++) {
117+
const page = copyManifestJSON.pages[i];
118+
if (page.source === source || (__frameIndex === 0 && (page.frames && page.frames[0] && page.frames[0].source === source))) {
119+
copyManifestJSON.pages.unshift(copyManifestJSON.pages.splice(i, 1)[0]);
120+
break;
113121
}
114-
});
122+
}
115123

116124
const { pages } = copyManifestJSON;
117125
// take out the page data prefetch and assign it to the root node

0 commit comments

Comments
 (0)