Skip to content

Commit

Permalink
feat: support mpa spm (#591)
Browse files Browse the repository at this point in the history
  • Loading branch information
SoloJiang authored Jan 21, 2021
1 parent c37a9e9 commit 03648ec
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 36 deletions.
2 changes: 2 additions & 0 deletions __tests__/dev-cases/with-rax-mpa.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ describe('should start web devServer: ', () => {
page = res.page;
browser = res.browser;
await page.waitForFunction(`document.getElementsByTagName('span').length > 0`);
expect(await page.$$attr('[name="data-spm"]', 'content')).toEqual(['a123']);
expect(await page.$$attr('body', 'data-spm')).toEqual(['b456']);
expect(await page.$$text('.title')).toStrictEqual(['Welcome to Your Rax App']);
}, 120000);

Expand Down
6 changes: 4 additions & 2 deletions examples/with-rax-mpa/src/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"source": "pages/Home/index",
"window": {
"title": "home"
}
},
"spm": "b456"
},
{
"path": "/about",
Expand All @@ -14,5 +15,6 @@
],
"window": {
"title": "Rax App"
}
},
"spm": "a123"
}
30 changes: 0 additions & 30 deletions examples/with-rax-mpa/src/document/index.jsx

This file was deleted.

2 changes: 1 addition & 1 deletion packages/plugin-rax-web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "build-plugin-rax-web",
"version": "1.2.0",
"version": "1.2.1",
"description": "rax web app plugin",
"main": "lib/index.js",
"scripts": {
Expand Down
2 changes: 2 additions & 0 deletions packages/plugin-rax-web/src/DocumentPlugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ export default class DocumentPlugin {
const htmlInfo: IHtmlInfo = {
...options.htmlInfo,
title: (targetPage && targetPage.window && targetPage.window.title) || options.htmlInfo.title,
spmA: options.staticConfig.spm,
spmB: targetPage && targetPage.spm,
};

if (this.documentPath) {
Expand Down
15 changes: 13 additions & 2 deletions packages/plugin-rax-web/src/utils/htmlStructure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,28 @@ let scripts = [];
let links = [];
let metas = [];

function addSpmA(spmA) {
if (!spmA) return '';
return `<meta name="data-spm" content="${spmA}" />`;
}

function addSpmB(spmB) {
if (!spmB) return '';
return `data-spm="${spmB}"`;
}

export function getBuiltInHtmlTpl(htmlInfo) {
const { doctype = '<!DOCTYPE html>', title } = htmlInfo;
const { doctype = '<!DOCTYPE html>', title, spmA, spmB } = htmlInfo;
return `
${doctype}
<html>
<head>
<meta charset="utf-8" />
${addSpmA(spmA)}
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no,viewport-fit=cover" />
<title>${title}</title>
</head>
<body>
<body ${addSpmB(spmB)}>
<div id="root"></div>
</body>
</html>
Expand Down
2 changes: 1 addition & 1 deletion packages/rax-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"build-plugin-rax-kraken": "1.1.0",
"build-plugin-rax-miniapp": "1.2.1",
"build-plugin-rax-pha": "1.2.1",
"build-plugin-rax-web": "1.2.0",
"build-plugin-rax-web": "1.2.1",
"build-plugin-rax-weex": "1.1.0",
"build-plugin-ssr": "1.2.0",
"chokidar": "^3.3.1",
Expand Down

0 comments on commit 03648ec

Please sign in to comment.