Skip to content

Commit

Permalink
feat: support swc (#4178)
Browse files Browse the repository at this point in the history
* feat: support swc

* feat: support swc

* chore: add default value

* chore: add context for modularImportRuntime

* chore: resolve conflict

* refactor: rework swc

* feat: swc plugin

* chore: rename example name

* chore: optimize code

* chore: update lock file

* chore: update version

* chore: optimize code

* chore: optimize code

* chore: optimize code

* chore: ci

* chore: optimize code

* chore: remove useless code
  • Loading branch information
SoloJiang authored Jul 12, 2021
1 parent 9916a62 commit 89f344a
Show file tree
Hide file tree
Showing 105 changed files with 5,705 additions and 3,501 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const tsRules = deepmerge(tslint, {
"no-use-before-define": 0,
"no-unused-vars": 0,
"@typescript-eslint/no-unused-vars": 1,
"@typescript-eslint/ban-ts-ignore": 0
},
});

Expand Down
17 changes: 17 additions & 0 deletions examples/basic-mpa-with-swc/build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"router": false,
"mpa": {
"openPage": "Dashboard",
"template": {
"web.html": ["Dashboard", "Home"]
},
"rewrites": {
"dashboard": "site/dashboard"
}
},
"swc": true,
"plugins": [],
"devServer": {
"writeToDisk": true
}
}
19 changes: 19 additions & 0 deletions examples/basic-mpa-with-swc/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "exmaple-basic-mpa",
"description": "",
"dependencies": {
"react": "^16.4.1",
"react-dom": "^16.4.1"
},
"devDependencies": {
"@types/react": "^16.9.13",
"@types/react-dom": "^16.9.4"
},
"scripts": {
"start": "icejs start",
"build": "icejs build"
},
"engines": {
"node": ">=8.0.0"
}
}
13 changes: 13 additions & 0 deletions examples/basic-mpa-with-swc/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="x-ua-compatible" content="ie=edge,chrome=1" />
<meta name="viewport" content="width=device-width" />
<title>icejs · mpa example</title>
</head>
<body>
<div>current page: <%= pageName %></div>
<div id="ice-container"></div>
</body>
</html>
14 changes: 14 additions & 0 deletions examples/basic-mpa-with-swc/public/web.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="x-ua-compatible" content="ie=edge,chrome=1" />
<meta name="viewport" content="width=device-width" />
<title>icejs · mpa example</title>
</head>

<body>
<div>using web.html template</div>
<div id="ice-container"></div>
</body>
</html>
6 changes: 6 additions & 0 deletions examples/basic-mpa-with-swc/sandbox.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"template": "node",
"container": {
"port": 3333
}
}
19 changes: 19 additions & 0 deletions examples/basic-mpa-with-swc/src/pages/Dashboard/app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { runApp, IAppConfig } from 'ice';
import React from 'react';
import routes from './routes';
import store from './store';

const Provider = store.Provider;

const appConfig: IAppConfig = {
router: {
routes
},
app: {
addProvider({ children }) {
return <Provider>{children}</Provider>;
}
}
};

runApp(appConfig);
18 changes: 18 additions & 0 deletions examples/basic-mpa-with-swc/src/pages/Dashboard/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';
import store from './store';

const Dashboard = () => {
const [pageState, pageActions] = store.useModel('counter');
return (
<>
<h2>Dashboard Page...</h2>
<div>
<button type="button" onClick={pageActions.increment}>+</button>
<span>{pageState.count}</span>
<button type="button" onClick={pageActions.decrement}>-</button>
</div>
</>
);
};

export default Dashboard;
23 changes: 23 additions & 0 deletions examples/basic-mpa-with-swc/src/pages/Dashboard/models/counter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export const delay = (time) => new Promise((resolve) => setTimeout(() => resolve(), time));

export default {
state: {
count: 0
},

reducers: {
increment (prevState) {
return { count: prevState.count + 1 };
},
decrement (prevState) {
return { count: prevState.count - 1 };
}
},

effects: (dispatch) => ({
async decrementAsync () {
await delay(10);
dispatch.counter.decrement();
},
}),
};
3 changes: 3 additions & 0 deletions examples/basic-mpa-with-swc/src/pages/Dashboard/routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Index from './index';

export default [{ path: '/', component: Index }];
7 changes: 7 additions & 0 deletions examples/basic-mpa-with-swc/src/pages/Dashboard/store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { createStore } from 'ice';
import counter from './models/counter';

const models = { counter };
const store = createStore(models);

export default store;
4 changes: 4 additions & 0 deletions examples/basic-mpa-with-swc/src/pages/Detail/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import React from 'react';
import ReactDOM from 'react-dom';

ReactDOM.render(<h2>Detail Page</h2>, document.body);
15 changes: 15 additions & 0 deletions examples/basic-mpa-with-swc/src/pages/Home/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';

const Home = () => {
return (
<>
<h2>Home Page</h2>
</>
);
};

Home.pageConfig = {
title: 'Home Page',
};

export default Home;
42 changes: 42 additions & 0 deletions examples/basic-mpa-with-swc/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"compileOnSave": false,
"buildOnSave": false,
"compilerOptions": {
"baseUrl": ".",
"outDir": "build",
"module": "esnext",
"target": "es6",
"jsx": "react",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"lib": [
"es6",
"dom"
],
"sourceMap": true,
"allowJs": true,
"rootDir": "./",
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noImplicitAny": false,
"importHelpers": true,
"strictNullChecks": true,
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": true,
"skipLibCheck": true,
"types": ["node"],
"paths": {
"@/*": [
"./src/*"
],
"ice": [
".ice/index.ts"
],
"ice/*": [
".ice/pages/*"
]
}
}
}
5 changes: 4 additions & 1 deletion examples/basic-mpa/build.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@
"dashboard": "site/dashboard"
}
},
"plugins": []
"plugins": [],
"devServer": {
"writeToDisk": true
}
}
10 changes: 0 additions & 10 deletions examples/basic-mpa/src/pages/Dashboard/app.ts

This file was deleted.

19 changes: 19 additions & 0 deletions examples/basic-mpa/src/pages/Dashboard/app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { runApp, IAppConfig } from 'ice';
import React from 'react';
import routes from './routes';
import store from './store';

const Provider = store.Provider;

const appConfig: IAppConfig = {
router: {
routes
},
app: {
addProvider({ children }) {
return <Provider>{children}</Provider>;
}
}
};

runApp(appConfig);
4 changes: 2 additions & 2 deletions examples/basic-mpa/src/pages/Dashboard/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { store } from 'ice/Dashboard';
import React from 'react';
import store from './store';

const Dashboard = () => {
const [pageState, pageActions] = store.useModel('counter');
Expand Down
7 changes: 7 additions & 0 deletions examples/basic-mpa/src/pages/Dashboard/store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { createStore } from 'ice';
import counter from './models/counter';

const models = { counter };
const store = createStore(models);

export default store;
2 changes: 1 addition & 1 deletion examples/basic-spa/build.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"modeConfig": {
"prod": {
"ignoreHtmlTemplate": true
"ignoreHtmlTemplate": false
}
},
"esbuild": {
Expand Down
2 changes: 1 addition & 1 deletion examples/basic-store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"react-test-renderer": "^16.13.1"
},
"scripts": {
"start": "icejs start --mode local",
"start": "../../packages/icejs/bin/ice-cli.js start --mode local",
"build": "icejs build",
"test": "icejs test"
},
Expand Down
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
"author": "ice-admin@alibaba-inc.com",
"license": "MIT",
"scripts": {
"setup": "rm -rf node_modules && yarn install --registry=https://registry.npm.taobao.org/ && npm run bootstrap",
"bootstrap": "npm run clean && npm run build",
"setup": "rm -rf node_modules && yarn install --registry=https://registry.npm.taobao.org/ && npm run build",
"watch": "ts-node ./scripts/watch.ts",
"build": "ts-node ./scripts/build.ts",
"version": "ts-node ./scripts/tag-version.ts",
Expand Down Expand Up @@ -73,8 +72,6 @@
},
"resolutions": {
"@typescript-eslint/eslint-plugin": "^4.0.0",
"@typescript-eslint/parser": "^4.0.0",
"@typescript-eslint/typescript-estree": "^4.0.0",
"miniapp-builder-shared": "^0.2.0"
"@typescript-eslint/parser": "^4.0.0"
}
}
13 changes: 0 additions & 13 deletions packages/babel-preset-ice/CHANGELOG.md

This file was deleted.

1 change: 0 additions & 1 deletion packages/babel-preset-ice/README.md

This file was deleted.

2 changes: 1 addition & 1 deletion packages/build-app-helpers/src/getEntriesByRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default (
route: IRoute,
rootDir: string
) => {
const entries:IEntry[] = [];
const entries: IEntry[] = [];
const { pageHeader, frames } = route;
const rootEntry = getEntry(route, rootDir);

Expand Down
10 changes: 10 additions & 0 deletions packages/build-app-helpers/src/modifySwcOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const { merge } = require('lodash');

export default function(config, swcOptions) {
config.module
.rule('jsx')
.use('swc-loader')
.tap((options) => {
return merge(options, swcOptions);
});
}
8 changes: 4 additions & 4 deletions packages/build-app-helpers/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export interface IEntry {
url?: string;
window?: {
title?: string;
[key: string]: string
}
[key: string]: string;
};
__frameIndex?: number;
__pageHeader?: boolean;
}
Expand All @@ -27,8 +27,8 @@ export interface IRoute {
pageSource?: string;
window?: {
title?: string;
[key: string]: string
}
[key: string]: string;
};
frames?: IRoute[];
pageHeader?: IPageHeader;
}
1 change: 1 addition & 0 deletions packages/build-babel-config/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# @builder/babel-config
Loading

0 comments on commit 89f344a

Please sign in to comment.