Skip to content

Commit

Permalink
Merge pull request #5090 from alibaba/release/2.5.0
Browse files Browse the repository at this point in the history
Release/2.5.0
  • Loading branch information
ClarkXia authored Jan 17, 2022
2 parents a33146c + 4f833cf commit 9431415
Show file tree
Hide file tree
Showing 185 changed files with 3,241 additions and 308 deletions.
17 changes: 17 additions & 0 deletions examples/basic-i18n/build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"plugins": [
[
"build-plugin-ice-i18n",
{
"locales": [
"zh-CN",
"en-US"
],
"defaultLocale": "zh-CN",
"redirect": true
}
]
],
"vite": false,
"ssr": "static"
}
18 changes: 18 additions & 0 deletions examples/basic-i18n/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"dependencies": {
"react": "^17.0.0",
"react-dom": "^17.0.0",
"react-intl": "^5.22.0"
},
"devDependencies": {
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0"
},
"scripts": {
"start": "RUNTIME_DEBUG=true ../../packages/icejs/bin/ice-cli.js start",
"build": "../../packages/icejs/bin/ice-cli.js build"
},
"engines": {
"node": ">=8.0.0"
}
}
Binary file added examples/basic-i18n/public/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions examples/basic-i18n/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!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 · i18n example</title>
</head>

<body>
<div id="ice-container"></div>
</body>

</html>
34 changes: 34 additions & 0 deletions examples/basic-i18n/src/app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { runApp, IAppConfig, useLocale, getDefaultLocale } from 'ice';
import { IntlProvider as ReactIntlProvider } from 'react-intl';
import { messages } from './locales';

function IntlProvider({ children }) {
const [locale] = useLocale();
const defaultLocale = getDefaultLocale();

return (
<ReactIntlProvider
messages={messages[locale]}
locale={locale}
defaultLocale={defaultLocale}
>
{children}
</ReactIntlProvider>
);
}

const appConfig: IAppConfig = {
router: {
type: 'browser',
basename: '/ice'
},
app: {
addProvider: ({ children }) => {
return (
<IntlProvider>{children}</IntlProvider>
);
}
}
};

runApp(appConfig);
26 changes: 26 additions & 0 deletions examples/basic-i18n/src/components/LocaleSwitcher.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { FormattedMessage } from 'react-intl';
import { useLocale, getAllLocales, Link, useLocation } from 'ice';

export default function LocaleSwitcher() {
const location = useLocation();

const [activeLocale, setLocale] = useLocale();
const allLocales = getAllLocales();
const otherLocales = allLocales.filter((locale) => activeLocale !== locale);
return (
<div>
<p><FormattedMessage id="localeSwitcher" />:</p>
<ul>
{
otherLocales.map((locale: string) => {
return (
<li key={locale}>
<Link to={location.pathname} onClick={() => setLocale(locale)}>{locale}</Link>
</li>
);
})
}
</ul>
</div>
);
}
5 changes: 5 additions & 0 deletions examples/basic-i18n/src/layouts/BasicLayout/index.module.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.basicLayout {
h1 {
color: red;
}
}
13 changes: 13 additions & 0 deletions examples/basic-i18n/src/layouts/BasicLayout/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { FormattedMessage } from 'react-intl';
import styles from './index.module.less';

function BasicLayout({ children }) {
return (
<main className={styles.basicLayout}>
<h1><FormattedMessage id="basicLayout" /></h1>
{children}
</main>
);
}

export default BasicLayout;
2 changes: 2 additions & 0 deletions examples/basic-i18n/src/locales/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './locales';
export * from './messages';
4 changes: 4 additions & 0 deletions examples/basic-i18n/src/locales/locales.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const LOCALES = {
ENGLISH: 'en-US',
ZH_CN: 'zh-CN'
};
22 changes: 22 additions & 0 deletions examples/basic-i18n/src/locales/messages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { LOCALES } from './locales';

export const messages = {
[LOCALES.ENGLISH]: {
homeTitle: 'Home',
aboutTitle: 'About',
currentLocale: 'Current locale',
defaultLocale: 'Default locale',
configuredLocales: 'Configured locales',
localeSwitcher: 'Locale Switcher',
basicLayout: 'BasicLayout',
},
[LOCALES.ZH_CN]: {
homeTitle: '首页',
aboutTitle: '关于',
currentLocale: '当前语言',
defaultLocale: '默认语言',
configuredLocales: '配置的语言',
localeSwitcher: '语言切换',
basicLayout: '主布局'
},
};
21 changes: 21 additions & 0 deletions examples/basic-i18n/src/pages/About/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { useLocale, getAllLocales, getDefaultLocale, Link } from 'ice';
import { FormattedMessage } from 'react-intl';
import LocaleSwitcher from '@/components/LocaleSwitcher';

function About() {
const [locale] = useLocale();
const allLocales = getAllLocales();
const defaultLocale = getDefaultLocale();
return (
<div>
<h2><FormattedMessage id="aboutTitle" /></h2>
<div><FormattedMessage id="configuredLocales" />: {JSON.stringify(allLocales)}</div>
<div><FormattedMessage id="defaultLocale" />: {defaultLocale}</div>
<div><FormattedMessage id="currentLocale" />: {locale}</div>
<Link to="/">Home</Link>
<LocaleSwitcher />
</div>
);
}

export default About;
25 changes: 25 additions & 0 deletions examples/basic-i18n/src/pages/Home/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { useLocale, getAllLocales, getDefaultLocale, Link, getLocale } from 'ice';
import { FormattedMessage } from 'react-intl';
import LocaleSwitcher from '@/components/LocaleSwitcher';

function Home() {
const [locale] = useLocale();
const allLocales = getAllLocales();
const defaultLocale = getDefaultLocale();
return (
<div>
<h2><FormattedMessage id="homeTitle" /></h2>
<div><FormattedMessage id="configuredLocales" />: {JSON.stringify(allLocales)}</div>
<div><FormattedMessage id="defaultLocale" />: {defaultLocale}</div>
<div><FormattedMessage id="currentLocale" />: {locale}</div>
<Link to="/about">About</Link>
<LocaleSwitcher />
</div>
);
}

Home.getInitialProps = function () {
console.log('getLocale in getInitialProps', getLocale());
};

export default Home;
25 changes: 25 additions & 0 deletions examples/basic-i18n/src/routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { IRouterConfig } from 'ice';
import BasicLayout from '@/layouts/BasicLayout';
import Home from '@/pages/Home';
import About from '@/pages/About';

const routerConfig: IRouterConfig[] = [
{
path: '/',
component: BasicLayout,
children: [
{
path: '/about',
exact: true,
component: About
},
{
path: '/',
exact: true,
component: Home,
},
]
},
];

export default routerConfig;
6 changes: 6 additions & 0 deletions examples/basic-i18n/src/typing.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
declare module '*.module.less' {
const classes: { [key: string]: string };
export default classes;
}

declare module '*.svg'
34 changes: 34 additions & 0 deletions examples/basic-i18n/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"compileOnSave": false,
"buildOnSave": false,
"compilerOptions": {
"baseUrl": ".",
"outDir": "build",
"module": "esnext",
"target": "es6",
"jsx": "react-jsx",
"moduleResolution": "node",
"allowSyntheticDefaultImports": 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/*"]
}
},
"include": ["src/*"],
"exclude": ["node_modules", "build", "public"]
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "exmaple-basic-mpa",
"name": "basic-mpa-vite",
"description": "",
"dependencies": {
"react": "^16.4.1",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
19 changes: 19 additions & 0 deletions examples/basic-mpa-webpack/build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"mpa": {
"openPage": "Dashboard",
"template": {
"web.html": [
"Dashboard",
"Home"
]
},
"rewrites": {
"dashboard": "site/dashboard"
}
},
"devServer": {
"devMiddleware": {
"writeToDisk": true
}
}
}
19 changes: 19 additions & 0 deletions examples/basic-mpa-webpack/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "basic-mpa-webpack",
"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": "../../packages/icejs/bin/ice-cli.js start",
"build": "../../packages/icejs/bin/ice-cli.js build"
},
"engines": {
"node": ">=8.0.0"
}
}
13 changes: 13 additions & 0 deletions examples/basic-mpa-webpack/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-webpack/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-webpack/sandbox.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"template": "node",
"container": {
"port": 3333
}
}
11 changes: 11 additions & 0 deletions examples/basic-mpa-webpack/src/pages/About/app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { runApp, IAppConfig } from 'ice';
import Index from './index';

const appConfig: IAppConfig = {
router: {
type: 'hash',
routes: [{ path: '/', component: Index }],
},
};

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

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

export default About;
Loading

0 comments on commit 9431415

Please sign in to comment.