Skip to content

Commit

Permalink
release: v3.5.3 (#720)
Browse files Browse the repository at this point in the history
* chore: remove template configuire

* feat: support config webpack for kuaishou and baidu miniapp
  • Loading branch information
SoloJiang authored May 13, 2021
1 parent a48398f commit 7f76926
Show file tree
Hide file tree
Showing 13 changed files with 118 additions and 161 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
## Changelog

## 3.5.3 (May 12 2021)

- Feat: support use build-plugin-rax-miniapp to config baidu/kuaishou miniapp
- Chore: change web.template to web.pha.template
- Chore: add builtInLibaray: false
- Fix: errorBoundary type define

## 3.5.2 (May 11 2021)

- Feat: support judge bytedance/baidu/kuaishou miniapp env
Expand Down
30 changes: 0 additions & 30 deletions examples/with-rax-pha/src/document/index.jsx

This file was deleted.

4 changes: 4 additions & 0 deletions packages/plugin-rax-app/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 6.3.2

- Feat: update dev and build log method for miniapps

## 6.3.1

- Chore: use constants from miniapp-builder-shared
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-rax-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "build-plugin-rax-app",
"version": "6.3.1",
"version": "6.3.2",
"description": "The basic webpack configuration for rax project",
"author": "Rax Team",
"main": "lib/index.js",
Expand Down Expand Up @@ -46,4 +46,4 @@
"url": "git@github.com:raxjs/rax-app.git"
},
"gitHead": "07ac7bb07162aac8c90778dd1de4a2060f8df498"
}
}
1 change: 1 addition & 0 deletions packages/plugin-rax-app/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = {
BAIDU_SMARTPROGRAM,
KUAISHOU_MINIPROGRAM,
QUICKAPP,
MINIAPP_PLATFORMS: [MINIAPP, WECHAT_MINIPROGRAM, BYTEDANCE_MICROAPP, BAIDU_SMARTPROGRAM, KUAISHOU_MINIPROGRAM],
GET_RAX_APP_WEBPACK_CONFIG: 'getRaxAppWebpackConfig',
DEV_URL_PREFIX: 'devUrlPrefix',
STATIC_CONFIG: 'staticConfig',
Expand Down
42 changes: 13 additions & 29 deletions packages/plugin-rax-app/src/setBuild.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const path = require('path');
const formatWebpackMessages = require('react-dev-utils/formatWebpackMessages');
const chalk = require('chalk');
const { platformMap } = require('miniapp-builder-shared');

const {
MINIAPP,
MINIAPP_PLATFORMS,
WEB,
WECHAT_MINIPROGRAM,
BYTEDANCE_MICROAPP,
WEEX,
KRAKEN,
} = require('./constants');
Expand Down Expand Up @@ -64,32 +64,16 @@ module.exports = (api) => {
console.log();
}

if (targets.includes(MINIAPP)) {
console.log(highlightPrint('[Alibaba MiniApp] Bundle at:'));
console.log(
' ',
chalk.underline.white(path.resolve(rootDir, outputDir, MINIAPP)),
);
console.log();
}

if (targets.includes(WECHAT_MINIPROGRAM)) {
console.log(highlightPrint('[WeChat MiniProgram] Bundle at:'));
console.log(
' ',
chalk.underline.white(path.resolve(rootDir, outputDir, WECHAT_MINIPROGRAM)),
);
console.log();
}

if (targets.includes(BYTEDANCE_MICROAPP)) {
console.log(highlightPrint('[ByteDance MicroApp] Bundle at:'));
console.log(
' ',
chalk.underline.white(path.resolve(rootDir, outputDir, BYTEDANCE_MICROAPP)),
);
console.log();
}
MINIAPP_PLATFORMS.forEach((miniappPlatform) => {
if (targets.includes(miniappPlatform)) {
console.log(highlightPrint(`[${platformMap[miniappPlatform].name}] Bundle at:`));
console.log(
' ',
chalk.underline.white(path.resolve(rootDir, outputDir, miniappPlatform)),
);
console.log();
}
});
}
});
};
Expand Down
43 changes: 13 additions & 30 deletions packages/plugin-rax-app/src/setDev.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ const qrcode = require('qrcode-terminal');
const path = require('path');
const fs = require('fs-extra');
const chokidar = require('chokidar');
const { platformMap } = require('miniapp-builder-shared');

const logWebpackConfig = require('./utils/logWebpackConfig');
const { MINIAPP, WEB, WECHAT_MINIPROGRAM, BYTEDANCE_MICROAPP, WEEX, KRAKEN, DEV_URL_PREFIX } = require('./constants');
const { MINIAPP_PLATFORMS, MINIAPP, WEB, WEEX, KRAKEN, DEV_URL_PREFIX } = require('./constants');
const generateTempFile = require('./utils/generateTempFile');

const highlightPrint = chalk.hex('#F4AF3D');
Expand Down Expand Up @@ -118,35 +119,17 @@ module.exports = function (api) {
);
}

if (targets.includes(MINIAPP)) {
const miniappOutputPath = path.resolve(rootDir, outputDir, MINIAPP);
devInfo.urls.miniapp = [miniappOutputPath];
console.log(
highlightPrint(' [Alibaba Miniapp] Use ali miniapp developer tools to open the following folder:'),
);
console.log(' ', chalk.underline.white(miniappOutputPath));
console.log();
}

if (targets.includes(WECHAT_MINIPROGRAM)) {
const wechatOutputPath = path.resolve(rootDir, outputDir, WECHAT_MINIPROGRAM);
devInfo.urls.wechat = [wechatOutputPath];
console.log(
highlightPrint(' [WeChat MiniProgram] Use wechat miniprogram developer tools to open the following folder:'),
);
console.log(' ', chalk.underline.white(wechatOutputPath));
console.log();
}

if (targets.includes(BYTEDANCE_MICROAPP)) {
const bytedanceOutputPath = path.resolve(rootDir, outputDir, BYTEDANCE_MICROAPP);
devInfo.urls.bytedance = [bytedanceOutputPath];
console.log(
highlightPrint(' [Bytedance Microapp] Use bytedance microapp developer tools to open the following folder:'),
);
console.log(' ', chalk.underline.white(bytedanceOutputPath));
console.log();
}
MINIAPP_PLATFORMS.forEach((miniappPlatform) => {
if (targets.includes(miniappPlatform)) {
const miniappOutputPath = path.resolve(rootDir, outputDir, miniappPlatform);
devInfo.urls[miniappPlatform === MINIAPP ? 'miniapp' : platformMap[miniappPlatform].type] = [miniappOutputPath];
console.log(
highlightPrint(` [${platformMap[miniappPlatform].name}] Use ${platformMap[miniappPlatform].name.toLowerCase()} developer tools to open the following folder:`),
);
console.log(' ', chalk.underline.white(miniappOutputPath));
console.log();
}
});

const appConfig = getValue('staticConfig');
const needGenerateMultipleManifest = pha && !appConfig.tabBar;
Expand Down
5 changes: 5 additions & 0 deletions packages/plugin-rax-pha/CHANELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## v1.4.2

- Chore: add builtin library to `scripts` field
- Chore: use `web.pha.template` instead of `web.template`

## v1.4.1

- Chore: Use the `template` field directly
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-rax-pha/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "build-plugin-rax-pha",
"version": "1.4.1",
"version": "1.4.2",
"description": "Rax PHA plugins",
"license": "BSD-3-Clause",
"main": "lib/index.js",
Expand Down
7 changes: 1 addition & 6 deletions packages/plugin-rax-pha/src/manifestHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function getRealPageInfo({ urlPrefix, urlSuffix = '' }, page) {
/*
* change page info
*/
function changePageInfo({ urlPrefix, urlSuffix = '', cdnPrefix, isTemplate, inlineStyle, api }, page, manifest) {
function changePageInfo({ urlPrefix, urlSuffix = '', cdnPrefix, isTemplate, inlineStyle, api }, page) {
const { applyMethod } = api;
const { source, name } = page;
if (!source && !name) {
Expand All @@ -123,11 +123,6 @@ function changePageInfo({ urlPrefix, urlSuffix = '', cdnPrefix, isTemplate, inli
if (isTemplate) {
if (custom) {
page.document = document;

if (manifest.built_in_library) {
// remove when has document
delete manifest.built_in_library;
}
} else {
// add script and stylesheet
page.script = `${cdnPrefix + entryName}.js`;
Expand Down
114 changes: 59 additions & 55 deletions packages/plugin-rax-pha/src/plugins/AppToManifestPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,17 @@ module.exports = class {
}

apply(compiler) {
const {
api,
builtInLibrary,
appWorkerPath,
} = this.options;
const { api, builtInLibrary = [], appWorkerPath } = this.options;

const { context, getValue } = api;
const { command, userConfig = {} } = context;
const { inlineStyle, web = {} } = userConfig;
const { template: isTemplate = true } = web;
const {
pha: { template: isTemplate = true },
} = web;
const isStart = command === 'start';

let {
cdnPrefix = '',
pagePrefix = '',
pageSuffix,
} = this.options;
let { cdnPrefix = '', pagePrefix = '', pageSuffix } = this.options;
if (isStart) {
cdnPrefix = `${getValue('devUrlPrefix')}/`;
pagePrefix = cdnPrefix;
Expand All @@ -52,20 +46,24 @@ module.exports = class {
}
}

if (builtInLibrary && builtInLibrary.length > 0) {
manifestJSON.built_in_library = builtInLibrary;
}
manifestJSON.scripts = [
...builtInLibrary.map((url) => `<script crossorigin="anonymous" src="${url}"></script>`),
...(manifestJSON.scripts || []),
];

// if has tabBar, do not generate multiple manifest.json
if (manifestJSON.tab_bar) {
manifestJSON = setRealUrlToManifest({
urlPrefix: pagePrefix,
urlSuffix: pageSuffix,
cdnPrefix,
isTemplate,
inlineStyle,
api,
}, manifestJSON);
manifestJSON = setRealUrlToManifest(
{
urlPrefix: pagePrefix,
urlSuffix: pageSuffix,
cdnPrefix,
isTemplate,
inlineStyle,
api,
},
manifestJSON,
);

compilation.assets['manifest.json'] = new RawSource(JSON.stringify(manifestJSON, null, 2));

Expand All @@ -75,41 +73,47 @@ module.exports = class {
target: 'web',
appJsonContent: appConfig,
});
entries.filter(({ __frameIndex, __pageHeader, __tabBar }) => {
if ((typeof __frameIndex !== 'undefined' && __frameIndex !== 0) || __pageHeader || __tabBar) {
return false;
}
return true;
}).forEach(({ source, entryName, __frameIndex }) => {
let copyManifestJSON = cloneDeep(manifestJSON);
copyManifestJSON.pages = copyManifestJSON.pages.filter((page) => {
// has frames
if (__frameIndex === 0) {
return !!(page.frames && page.frames[0] && page.frames[0].source === source);
} else {
return page.source === source;
entries
.filter(({ __frameIndex, __pageHeader, __tabBar }) => {
if ((typeof __frameIndex !== 'undefined' && __frameIndex !== 0) || __pageHeader || __tabBar) {
return false;
}
return true;
})
.forEach(({ source, entryName, __frameIndex }) => {
let copyManifestJSON = cloneDeep(manifestJSON);
copyManifestJSON.pages = copyManifestJSON.pages.filter((page) => {
// has frames
if (__frameIndex === 0) {
return !!(page.frames && page.frames[0] && page.frames[0].source === source);
} else {
return page.source === source;
}
});

const { pages } = copyManifestJSON;
// take out the page data prefetch and assign it to the root node
if (pages && pages[0] && pages[0].data_prefetch) {
copyManifestJSON.data_prefetch = pages[0].data_prefetch;
delete pages[0].data_prefetch;
}
});

const { pages } = copyManifestJSON;
// take out the page data prefetch and assign it to the root node
if (pages && pages[0] && pages[0].data_prefetch) {
copyManifestJSON.data_prefetch = pages[0].data_prefetch;
delete pages[0].data_prefetch;
}

copyManifestJSON = setRealUrlToManifest({
urlPrefix: pagePrefix,
urlSuffix: pageSuffix,
cdnPrefix,
isTemplate,
inlineStyle,
api,
}, copyManifestJSON);
compilation.assets[`${entryName}-manifest.json`] = new RawSource(JSON.stringify(copyManifestJSON, null, 2));

devUrls.push(`${cdnPrefix}${entryName}-manifest.json?pha=true`);
});
copyManifestJSON = setRealUrlToManifest(
{
urlPrefix: pagePrefix,
urlSuffix: pageSuffix,
cdnPrefix,
isTemplate,
inlineStyle,
api,
},
copyManifestJSON,
);

compilation.assets[`${entryName}-manifest.json`] = new RawSource(JSON.stringify(copyManifestJSON, null, 2));

devUrls.push(`${cdnPrefix}${entryName}-manifest.json?pha=true`);
});
}

if (isStart) {
Expand Down
Loading

0 comments on commit 7f76926

Please sign in to comment.