Skip to content

Commit

Permalink
Merge pull request #3292 from alibaba/release-next
Browse files Browse the repository at this point in the history
  • Loading branch information
ClarkXia authored Jun 30, 2020
2 parents e43913b + 507624d commit b987b09
Show file tree
Hide file tree
Showing 29 changed files with 109 additions and 48 deletions.
14 changes: 14 additions & 0 deletions docs/guide/advance/mpa.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,20 @@ createApp(appConfig);
关于状态管理的更多内容,请查看文档 [状态管理](/docs/guide/basic/store.md)

## 其他

### 指定入口

默认 MPA 应用在开发阶段会启动所有页面,如果你只想调试某个页面,可以通过指定 `--mpa-entry` 来启动。

通过命令行参数指定启动的页面:

```bash
"scripts": {
"start": "icejs start --mpa-entry dashboard",
}
```

只需要这么简单,你的 SPA 应用就可以变成 MPA 应用了。

* MPA 项目示例 [详见](https://github.com/ice-lab/icejs/tree/master/examples/basic-mpa)
2 changes: 1 addition & 1 deletion docs/guide/basic/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ icejs 中一般不允许修改该配置。
- 类型:`array`
- 默认值:`[]`

默认情况下 babel-loader 会忽略所有 node_modules 目录下的所有文件。如果需要 babel 去编译 node_modules 下的指定文件,可以在这个配置快捷添加。
默认情况下 babel-loader 会编译相关模块以兼容 IE11。如果需要 babel 去编译 node_modules 下的指定文件,可以在这个配置快捷添加。

比如想编译 node_modules 下的 @alifd/next 依赖,可以进行如下设置:

Expand Down
4 changes: 3 additions & 1 deletion examples/basic-auth/src/routes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import Home from '@/pages/Home';
import { lazy } from 'ice';

const Home = lazy(() => import('@/pages/Home'));

export default [
{
Expand Down
2 changes: 1 addition & 1 deletion examples/basic-mpa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"@types/react-dom": "^16.9.4"
},
"scripts": {
"start": "icejs start",
"start": "icejs start --mpa-entry Dashboard",
"build": "icejs build"
},
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.6.0",
"version": "1.6.1",
"npmClient": "yarn",
"useWorkspaces": true,
"packages": [
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ice.js",
"private": true,
"version": "1.5.0",
"version": "1.6.0",
"workspaces": [
"packages/*"
],
Expand Down
2 changes: 1 addition & 1 deletion packages/create-ice/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-ice",
"version": "1.6.0",
"version": "1.6.1",
"description": "npm init ice",
"author": "ice-admin@alibaba-inc.com",
"homepage": "",
Expand Down
22 changes: 11 additions & 11 deletions packages/icejs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ice.js",
"version": "1.6.0",
"version": "1.6.1",
"description": "command line interface and builtin plugin for icejs",
"author": "ice-admin@alibaba-inc.com",
"homepage": "",
Expand All @@ -25,16 +25,16 @@
},
"dependencies": {
"@alib/build-scripts": "^0.1.13",
"build-plugin-ice-config": "1.6.0",
"build-plugin-ice-core": "1.6.0",
"build-plugin-ice-helpers": "1.6.0",
"build-plugin-ice-logger": "1.6.0",
"build-plugin-ice-mpa": "1.6.0",
"build-plugin-ice-request": "1.6.0",
"build-plugin-ice-router": "1.6.0",
"build-plugin-ice-ssr": "1.6.0",
"build-plugin-ice-store": "1.6.0",
"build-plugin-react-app": "1.6.0",
"build-plugin-ice-config": "1.6.1",
"build-plugin-ice-core": "1.6.1",
"build-plugin-ice-helpers": "1.6.1",
"build-plugin-ice-logger": "1.6.1",
"build-plugin-ice-mpa": "1.6.1",
"build-plugin-ice-request": "1.6.1",
"build-plugin-ice-router": "1.6.1",
"build-plugin-ice-ssr": "1.6.1",
"build-plugin-ice-store": "1.6.1",
"build-plugin-react-app": "1.6.1",
"chokidar": "^3.3.1",
"commander": "^5.0.0",
"detect-port": "^1.3.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-auth/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "build-plugin-ice-auth",
"version": "1.6.0",
"version": "1.6.1",
"description": "",
"author": "ice-admin@alibaba-inc.com",
"homepage": "https://github.com/alibaba/ice#readme",
Expand Down
9 changes: 5 additions & 4 deletions packages/plugin-auth/src/module.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,23 @@ import AuthStore from '$ice/authStore';

const wrapperComponentFn = (authConfig) => (PageComponent) => {
const { pageConfig = {} } = PageComponent;
const [auth] = AuthStore.useModel('auth');

const AuthWrapperedComponent = (props) => {
const { auth, ...rest } = props;
const [authState] = auth;
const pageConfigAuth = pageConfig.auth;
if(pageConfigAuth && !Array.isArray(pageConfigAuth)) {
throw new Error('pageConfig.auth must be an array');
}
const hasAuth = Array.isArray(pageConfigAuth)
? Object.keys(auth).filter(item => pageConfigAuth.includes(item) ? auth[item] : false).length
? Object.keys(authState).filter(item => pageConfigAuth.includes(item) ? authState[item] : false).length
: true;
if (!hasAuth) {
return authConfig.NoAuthFallback ? authConfig.NoAuthFallback : null;
}
return <PageComponent {...props} />;
return <PageComponent {...rest} />;
};
return AuthWrapperedComponent;
return AuthStore.withModel('auth')(AuthWrapperedComponent);
};

export default ({ context, appConfig, addProvider, wrapperRouteComponent }) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "build-plugin-ice-config",
"version": "1.6.0",
"version": "1.6.1",
"description": "Define application config in icejs",
"author": "ice-admin@alibaba-inc.com",
"homepage": "",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "build-plugin-ice-core",
"version": "1.6.0",
"version": "1.6.1",
"description": "the core plugin for icejs.",
"author": "ice-admin@alibaba-inc.com",
"homepage": "",
Expand Down
4 changes: 4 additions & 0 deletions packages/plugin-core/src/utils/getRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ function getRoutes({ rootDir, tempDir, configPath, projectType, isMpa }: IParams
const routesTempPath = path.join(tempDir, 'routes.ts');
fse.writeFileSync(routesTempPath, 'export default [];', 'utf-8');
configPath = routesTempPath;
return {
routesPath: configPath,
isConfigRoutes: true
};
}

const routesPath = configPath
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-fast-refresh/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "build-plugin-fast-refresh",
"version": "1.6.0",
"version": "1.6.1",
"description": "A Webpack plugin to enable Fast Refresh (also previously known as Hot Reloading) for React",
"author": "思忠 <chenbinbin.cb@alibaba-inc.com>",
"homepage": "https://github.com/alibaba/ice#readme",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-helpers/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "build-plugin-ice-helpers",
"version": "1.6.0",
"version": "1.6.1",
"description": "builtin helpers in icejs",
"author": "ice-admin@alibaba-inc.com",
"homepage": "",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-icestark/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "build-plugin-icestark",
"version": "1.6.0",
"version": "1.6.1",
"description": "Easy use `icestark` in icejs.",
"author": "ice-admin@alibaba-inc.com",
"homepage": "",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-logger/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "build-plugin-ice-logger",
"version": "1.6.0",
"version": "1.6.1",
"description": "builtin logger in icejs",
"author": "ice-admin@alibaba-inc.com",
"homepage": "",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-mpa/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "build-plugin-ice-mpa",
"version": "1.6.0",
"version": "1.6.1",
"description": "enable mpa project for icejs framework",
"author": "ice-admin@alibaba-inc.com",
"homepage": "",
Expand Down
45 changes: 36 additions & 9 deletions packages/plugin-mpa/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,20 @@ import { IPlugin } from '@alib/build-scripts';
import * as path from 'path';
import * as fs from 'fs-extra';

const plugin: IPlugin = ({ context, registerUserConfig, modifyUserConfig }) => {
const { rootDir, userConfig } = context;
const plugin: IPlugin = ({ context, registerUserConfig, registerCliOption, modifyUserConfig, log }) => {
const { rootDir, userConfig, commandArgs } = context;

// register mpa in build.json
registerUserConfig({
name: 'mpa',
validation: 'boolean',
});

// support --mpa-entry to specify mpa entry
registerCliOption({
name: 'mpa-entry',
commands: ['start'],
});

if (userConfig.mpa) {
const pagesPath = path.join(rootDir, 'src/pages');
Expand All @@ -12,7 +24,7 @@ const plugin: IPlugin = ({ context, registerUserConfig, modifyUserConfig }) => {
.filter(page => !/^[._]/.test(page))
.map(page => path.parse(page).name)
: [];
const mpaEntry = pages.reduce((acc, pageName) => {
let entries = pages.reduce((acc, pageName) => {
const entryName = pageName.toLocaleLowerCase();
const pageEntry = getPageEntry(rootDir, pageName);
if (!pageEntry) return acc;
Expand All @@ -21,14 +33,29 @@ const plugin: IPlugin = ({ context, registerUserConfig, modifyUserConfig }) => {
[entryName]: `src/pages/${pageName}/${pageEntry}`
};
}, {});

const finalEntries = {};
if (commandArgs.mpaEntry) {
const arr = commandArgs.mpaEntry.split(',');
arr.forEach((pageName) => {
const entryName = pageName.toLocaleLowerCase();
if (entries[entryName]) {
finalEntries[entryName] = entries[entryName];
}
});
if (Object.keys(finalEntries).length > 0) {
entries = finalEntries;
log.info('已启用 --map-entry 指定多页入口 \n', JSON.stringify(entries));
} else {
log.warn(`--map-entry ${commandArgs.entry}`, '未能匹配到指定入口');
}
} else {
log.info('使用多页面模式 \n', JSON.stringify(entries));
}

// modify entry
modifyUserConfig('entry', mpaEntry);
modifyUserConfig('entry', entries);
}
// register mpa in build.json
registerUserConfig({
name: 'mpa',
validation: 'boolean',
});
};

function getPageEntry(rootDir, pageName) {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-prerender/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "build-plugin-prerender",
"version": "1.6.0",
"version": "1.6.1",
"description": "Prerender Plugin",
"main": "lib/index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-react-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "build-plugin-react-app",
"version": "1.6.0",
"version": "1.6.1",
"description": "The basic webpack configuration for ice project",
"author": "ice-admin@alibaba-inc.com",
"main": "src/index.js",
Expand Down
15 changes: 14 additions & 1 deletion packages/plugin-react-app/src/userConfig/compileDependencies.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
const defaultCompileDependencies = [
'ansi-regex',
'ansi-styles',
'chalk',
'query-string',
'react-dev-utils',
'split-on-first',
'strict-uri-encode',
'strip-ansi'
];
module.exports = (config, compileDependencies) => {
const matchExclude = (filepath) => {
// exclude the core-js for that it will fail to run in IE
if (filepath.match(/core-js/))
return true;
// compile build-plugin module for default
const deps = [/build-plugin.*module/].concat(compileDependencies).map(dep => {
const deps = [/build-plugin.*module/].concat(defaultCompileDependencies, compileDependencies).map(dep => {
if (dep instanceof RegExp) {
return dep.source;
} else if (typeof dep === 'string') {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-react-app/src/userConfig/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports = (config, value, context) => {
}

const entryNames = Object.keys(entry);
const isMultiEntry = entryNames.length > 1;
const isMultiEntry = entryNames.length > 1 || userConfig.mpa;
let pluginConfig = {};
if (config.plugins.get('HtmlWebpackPlugin')) {
pluginConfig = { ...config.plugin('HtmlWebpackPlugin').get('args')[0] };
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-rematch/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "build-plugin-ice-rematch",
"version": "1.6.0",
"version": "1.6.1",
"description": "Easy use `rematch` in icejs",
"author": "ice-admin@alibaba-inc.com",
"homepage": "",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-request/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "build-plugin-ice-request",
"version": "1.6.0",
"version": "1.6.1",
"description": "request for build-plugin-ice-request",
"author": "ice-admin@alibaba-inc.com",
"homepage": "",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-router/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "build-plugin-ice-router",
"version": "1.6.0",
"version": "1.6.1",
"description": "build-plugin-ice-router",
"author": "ice-admin@alibaba-inc.com",
"homepage": "",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-service/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "build-plugin-ice-service",
"version": "1.6.0",
"version": "1.6.1",
"description": "service pulgin",
"author": "ice-admin@alibaba-inc.com",
"homepage": "https://github.com/ice-lab/icejs#readme",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-ssr/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "build-plugin-ice-ssr",
"version": "1.6.0",
"version": "1.6.1",
"description": "ssr plugin",
"author": "ice-admin@alibaba-inc.com",
"homepage": "",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-store/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "build-plugin-ice-store",
"version": "1.6.0",
"version": "1.6.1",
"description": "builtin `icestore` in icejs",
"author": "ice-admin@alibaba-inc.com",
"homepage": "",
Expand Down

0 comments on commit b987b09

Please sign in to comment.