diff --git a/examples/with-rax-mpa/README.md b/examples/with-rax-mpa/README.md
deleted file mode 100644
index 98a3bb4ecc..0000000000
--- a/examples/with-rax-mpa/README.md
+++ /dev/null
@@ -1,3 +0,0 @@
-# with rax
-
-https://github.com/ice-lab/icejs/tree/master/examples
diff --git a/examples/with-rax-mpa/build.json b/examples/with-rax-mpa/build.json
deleted file mode 100644
index 6a51d5c44c..0000000000
--- a/examples/with-rax-mpa/build.json
+++ /dev/null
@@ -1,11 +0,0 @@
-{
- /*"web": {
- "mpa": true
- },
- "weex": {
- "mpa": true
- }, */
- "plugins": ["build-plugin-mpa"],
- "targets": ["web"],
- "inlineStyle": true
-}
diff --git a/examples/with-rax-mpa/package.json b/examples/with-rax-mpa/package.json
deleted file mode 100644
index f077cb3020..0000000000
--- a/examples/with-rax-mpa/package.json
+++ /dev/null
@@ -1,22 +0,0 @@
-{
- "name": "with-rax-mpa",
- "description": "rax mpa example",
- "dependencies": {
- "rax": "^1.1.0",
- "rax-document": "^0.1.0",
- "rax-image": "^2.0.0",
- "rax-link": "^1.0.1",
- "rax-text": "^1.0.0",
- "rax-view": "^1.0.0"
- },
- "devDependencies": {
- "@types/rax": "^1.0.0"
- },
- "scripts": {
- "start": "rax-app start",
- "build": "rax-app build"
- },
- "engines": {
- "node": ">=8.0.0"
- }
-}
diff --git a/examples/with-rax-mpa/src/app.json b/examples/with-rax-mpa/src/app.json
deleted file mode 100644
index 21d71dd98e..0000000000
--- a/examples/with-rax-mpa/src/app.json
+++ /dev/null
@@ -1,15 +0,0 @@
-{
- "routes": [
- {
- "path": "/",
- "source": "pages/Home/index"
- },
- {
- "path": "/about",
- "source": "/pages/About/index"
- }
- ],
- "window": {
- "title": "Rax App"
- }
-}
diff --git a/examples/with-rax-mpa/src/app.ts b/examples/with-rax-mpa/src/app.ts
deleted file mode 100644
index 9d23330756..0000000000
--- a/examples/with-rax-mpa/src/app.ts
+++ /dev/null
@@ -1,15 +0,0 @@
-import { runApp } from 'rax-app';
-
-runApp({
- app: {
- onShow() {
- console.log('app show...');
- },
- onHide() {
- console.log('app hide...');
- }
- },
- router: {
- basename: '/home'
- }
-});
diff --git a/examples/with-rax-mpa/src/components/Logo/index.css b/examples/with-rax-mpa/src/components/Logo/index.css
deleted file mode 100644
index 2f8d8d1144..0000000000
--- a/examples/with-rax-mpa/src/components/Logo/index.css
+++ /dev/null
@@ -1,5 +0,0 @@
-.logo {
- width: 200rpx;
- height: 180rpx;
- margin-bottom: 20rpx;
-}
\ No newline at end of file
diff --git a/examples/with-rax-mpa/src/components/Logo/index.tsx b/examples/with-rax-mpa/src/components/Logo/index.tsx
deleted file mode 100644
index 3019027efd..0000000000
--- a/examples/with-rax-mpa/src/components/Logo/index.tsx
+++ /dev/null
@@ -1,21 +0,0 @@
-import { createElement, PureComponent } from 'rax';
-import Image from 'rax-image';
-
-import './index.css';
-
-class Logo extends PureComponent {
- public render() {
- const source = {
- uri: '//gw.alicdn.com/tfs/TB1MRC_cvb2gK0jSZK9XXaEgFXa-1701-1535.png',
- };
- console.log('with router =>', this.props);
- return (
-
- );
- }
-}
-
-export default Logo;
diff --git a/examples/with-rax-mpa/src/document/index.tsx b/examples/with-rax-mpa/src/document/index.tsx
deleted file mode 100644
index 4eeed411e3..0000000000
--- a/examples/with-rax-mpa/src/document/index.tsx
+++ /dev/null
@@ -1,21 +0,0 @@
-import { createElement } from 'rax';
-import { Root, Style, Script } from 'rax-document';
-
-function Document() {
- return (
-
-
-
-
- @ali/demo-app
-
-
-
- {/* root container */}
-
-
-
-
- );
-}
-export default Document;
diff --git a/examples/with-rax-mpa/src/pages/About/app.json b/examples/with-rax-mpa/src/pages/About/app.json
deleted file mode 100644
index 8a6f706b46..0000000000
--- a/examples/with-rax-mpa/src/pages/About/app.json
+++ /dev/null
@@ -1,11 +0,0 @@
-{
- "routes": [
- {
- "path": "/",
- "source": "/pages/About/index"
- }
- ],
- "window": {
- "title": "Rax App 2"
- }
-}
diff --git a/examples/with-rax-mpa/src/pages/About/app.ts b/examples/with-rax-mpa/src/pages/About/app.ts
deleted file mode 100644
index b42197d622..0000000000
--- a/examples/with-rax-mpa/src/pages/About/app.ts
+++ /dev/null
@@ -1,15 +0,0 @@
-import { runApp } from 'rax-app';
-import staticConfig from './app.json';
-
-console.log('==', staticConfig);
-
-runApp({
- app: {
- onShow() {
- console.log('app show...');
- },
- onHide() {
- console.log('app hide...');
- }
- },
-}, staticConfig);
diff --git a/examples/with-rax-mpa/src/pages/About/index.css b/examples/with-rax-mpa/src/pages/About/index.css
deleted file mode 100644
index 85ae2d0722..0000000000
--- a/examples/with-rax-mpa/src/pages/About/index.css
+++ /dev/null
@@ -1,16 +0,0 @@
-.about {
- align-items: center;
- margin-top: 200rpx;
-}
-
-.title {
- font-size: 45rpx;
- font-weight: bold;
- margin: 20rpx 0;
-}
-
-.info {
- font-size: 36rpx;
- margin: 8rpx 0;
- color: #555;
-}
diff --git a/examples/with-rax-mpa/src/pages/About/index.tsx b/examples/with-rax-mpa/src/pages/About/index.tsx
deleted file mode 100644
index 4286e5dd55..0000000000
--- a/examples/with-rax-mpa/src/pages/About/index.tsx
+++ /dev/null
@@ -1,18 +0,0 @@
-import { createElement, PureComponent } from 'rax';
-import View from 'rax-view';
-import Text from 'rax-text';
-
-import './index.css';
-
-class About extends PureComponent {
- public render() {
- return (
-
- About Page!!!
- (this.props as any).history.push('/')}>Go Home
-
- );
- }
-}
-
-export default About;
diff --git a/examples/with-rax-mpa/src/pages/Home/index.css b/examples/with-rax-mpa/src/pages/Home/index.css
deleted file mode 100644
index cd3b101696..0000000000
--- a/examples/with-rax-mpa/src/pages/Home/index.css
+++ /dev/null
@@ -1,16 +0,0 @@
-.home {
- align-items: center;
- margin-top: 200rpx;
-}
-
-.title {
- font-size: 45rpx;
- font-weight: bold;
- margin: 20rpx 0;
-}
-
-.info {
- font-size: 36rpx;
- margin: 8rpx 0;
- color: #555;
-}
diff --git a/examples/with-rax-mpa/src/pages/Home/index.tsx b/examples/with-rax-mpa/src/pages/Home/index.tsx
deleted file mode 100644
index 8d883ecda6..0000000000
--- a/examples/with-rax-mpa/src/pages/Home/index.tsx
+++ /dev/null
@@ -1,18 +0,0 @@
-import { createElement } from 'rax';
-import View from 'rax-view';
-import Text from 'rax-text';
-import Logo from '@/components/Logo';
-
-import './index.css';
-
-export default function Home(props) {
- console.log(props);
- return (
-
-
- 1321321
- Welcome to Your Rax App!!!
- More information about Rax
-
- );
-}
diff --git a/examples/with-rax-mpa/tsconfig.json b/examples/with-rax-mpa/tsconfig.json
deleted file mode 100644
index c0dfde13ef..0000000000
--- a/examples/with-rax-mpa/tsconfig.json
+++ /dev/null
@@ -1,20 +0,0 @@
-{
- "compilerOptions": {
- "module": "esNext",
- "target": "es2015",
- "outDir": "build",
- "jsx": "preserve",
- "jsxFactory": "createElement",
- "moduleResolution": "node",
- "sourceMap": true,
- "alwaysStrict": true,
- "baseUrl": ".",
- "paths": {
- "@/*": ["./src/*"],
- "rax-app": [".rax/index.ts"],
- "rax": ["node_modules/@types/rax"]
- }
- },
- "include": ["src/*", ".rax"],
- "exclude": ["build"]
-}
diff --git a/packages/build-mpa-config/package.json b/packages/build-mpa-config/package.json
index c93007ffad..793772f900 100644
--- a/packages/build-mpa-config/package.json
+++ b/packages/build-mpa-config/package.json
@@ -23,6 +23,7 @@
"test": "echo \"Error: run tests from root\" && exit 1"
},
"dependencies": {
- "fs-extra": "^8.1.0"
+ "fs-extra": "^8.1.0",
+ "loader-utils": "^2.0.0"
}
}
diff --git a/packages/build-mpa-config/src/index.ts b/packages/build-mpa-config/src/index.ts
index 260e5cff41..26a11b540a 100644
--- a/packages/build-mpa-config/src/index.ts
+++ b/packages/build-mpa-config/src/index.ts
@@ -3,11 +3,13 @@ import getEntries from './getEntries';
interface ConfigOptions {
rootDir: string;
- filterEntries?: Function;
+ filterEntries: Function;
+ type: string;
+ framework: string;
}
const setMPAConfig = (config, options: ConfigOptions) => {
- const { rootDir, filterEntries = (v) => v } = options || {};
+ const { rootDir, type = 'web', framework = 'rax', filterEntries = (v) => v } = options || {};
let mpaEntries = getEntries(rootDir);
mpaEntries = filterEntries(mpaEntries);
// clear entry points
@@ -17,7 +19,7 @@ const setMPAConfig = (config, options: ConfigOptions) => {
mpaEntries.forEach((entry) => {
const { entryName, entryPath, pageName } = entry;
const pageEntry = path.join(rootDir, 'src/pages', entryPath);
- config.entry(entryName).add(pageEntry);
+ config.entry(entryName).add(/app\.(t|j)sx?$/.test(entryPath) ? pageEntry : `${require.resolve('./mpa-loader')}?type=${type}&framework=${framework}!${pageEntry}`);
// get page paths for rule match
const matchStr = `src/pages/${pageName}`;
matchStrs.push(process.platform === 'win32' ? matchStr.replace(/\//g, '\\\\') : matchStr);
diff --git a/packages/build-mpa-config/src/mpa-loader.ts b/packages/build-mpa-config/src/mpa-loader.ts
new file mode 100644
index 0000000000..3dd9804ca5
--- /dev/null
+++ b/packages/build-mpa-config/src/mpa-loader.ts
@@ -0,0 +1,41 @@
+import { getOptions } from 'loader-utils';
+
+function mpaLoader() {
+ const options = getOptions(this) || {};
+ const framework = options.framework || 'rax';
+ const withSSR = process.env.__SSR_ENABLED__ === 'true';
+ let appRender = '';
+ if (options.type === 'weex') {
+ appRender = 'render(createElement(Entry), null, { driver: DriverUniversal });';
+ } else {
+ appRender = `
+ const renderApp = async function() {
+ // process App.getInitialProps
+ if (withSSR && window.__INITIAL_DATA__ && window.__INITIAL_DATA__.pageData !== null) {
+ Object.assign(comProps, window.__INITIAL_DATA__.pageData);
+ } else if (Component.getInitialProps) {
+ Object.assign(comProps, await Component.getInitialProps());
+ }
+ render(createElement(Entry), document.getElementById("root"), { driver: DriverUniversal, hydrate: withSSR });
+ }
+
+ renderApp();
+ `;
+ }
+ const source = `
+ import { render, createElement } from '${framework}';
+ import Component from '${process.platform === 'win32' ? this.resourcePath.replace(/\//g, '\\\\') : this.resourcePath}';
+ import DriverUniversal from 'driver-universal';
+ const withSSR = ${withSSR};
+
+ const comProps = {};
+
+ function Entry() {
+ return createElement(Component, comProps);
+ }
+ ${appRender}
+ `;
+ return source;
+}
+
+export default mpaLoader;
\ No newline at end of file