Skip to content

Commit

Permalink
Merge pull request #6881 from alibaba/release/next
Browse files Browse the repository at this point in the history
Release 3.4.8
  • Loading branch information
ClarkXia authored May 7, 2024
2 parents 8fd6343 + 61ed9f0 commit 280b290
Show file tree
Hide file tree
Showing 57 changed files with 704 additions and 64 deletions.
1 change: 1 addition & 0 deletions examples/with-intl/.browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
chrome 55
6 changes: 6 additions & 0 deletions examples/with-intl/ice.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { defineConfig } from '@ice/app';
import intl from '@ice/plugin-intl';

export default defineConfig(() => ({
plugins: [intl()],
}));
23 changes: 23 additions & 0 deletions examples/with-intl/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "@examples/with-intl",
"version": "1.0.0",
"private": true,
"scripts": {
"start": "ice start",
"build": "ice build"
},
"description": "",
"author": "",
"license": "MIT",
"dependencies": {
"@ice/app": "workspace:*",
"@ice/plugin-intl": "workspace:*",
"@ice/runtime": "workspace:*",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.2"
}
}
Binary file added examples/with-intl/public/favicon.ico
Binary file not shown.
8 changes: 8 additions & 0 deletions examples/with-intl/src/app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineAppConfig } from 'ice';
import type { LocaleConfig } from '@ice/plugin-intl/types';

export default defineAppConfig(() => ({}));

export const locale: LocaleConfig = {
getLocale: () => 'en-US',
};
22 changes: 22 additions & 0 deletions examples/with-intl/src/document.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Meta, Title, Links, Main, Scripts } from 'ice';

function Document() {
return (
<html>
<head>
<meta charSet="utf-8" />
<meta name="description" content="ICE Demo" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<Meta />
<Title />
<Links />
</head>
<body>
<Main />
<Scripts />
</body>
</html>
);
}

export default Document;
3 changes: 3 additions & 0 deletions examples/with-intl/src/global.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
font-size: 14px;
}
3 changes: 3 additions & 0 deletions examples/with-intl/src/locales/en-US.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
new: 'New',
};
3 changes: 3 additions & 0 deletions examples/with-intl/src/locales/zh-CN.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"new": "新建"
}
10 changes: 10 additions & 0 deletions examples/with-intl/src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { intl } from 'ice';

export default function Home() {
return (
<>
<h1>home</h1>
<button>{intl.formatMessage({ id: 'new' })}</button>
</>
);
}
1 change: 1 addition & 0 deletions examples/with-intl/src/typings.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="@ice/app/types" />
32 changes: 32 additions & 0 deletions examples/with-intl/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"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,
"paths": {
"@/*": ["./src/*"],
"ice": [".ice"]
}
},
"include": ["src", ".ice", "ice.config.*"],
"exclude": ["build", "public"]
}
2 changes: 1 addition & 1 deletion examples/with-request/src/app.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { request as requestAPI, defineDataLoader } from 'ice';
import { defineRequestConfig } from '@ice/plugin-request/types';

export const dataLader = defineDataLoader(async () => {
export const dataLoader = defineDataLoader(async () => {
try {
return await requestAPI('/user');
} catch (err) {
Expand Down
16 changes: 16 additions & 0 deletions packages/ice/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# Changelog

## 3.4.8

### Patch Changes

- 8dada9b6: feat: support generator api to inject code in server entry
- 5c40dc93: fix: do not remove request config of dataLoader compilation in speedup mode
- 11a87dc6: feat: support spilt page chunk in cjs format
- Updated dependencies [e4a32686]
- Updated dependencies [e78c7d22]
- Updated dependencies [e858a522]
- Updated dependencies [a805fa95]
- @ice/shared-config@1.2.7
- @ice/runtime@1.4.7
- @ice/rspack-config@1.1.7
- @ice/webpack-config@1.1.14

## 3.4.7

### Patch Changes
Expand Down
10 changes: 5 additions & 5 deletions packages/ice/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ice/app",
"version": "3.4.7",
"version": "3.4.8",
"description": "provide scripts and configuration used by web framework ice",
"type": "module",
"main": "./esm/index.js",
Expand Down Expand Up @@ -49,10 +49,10 @@
"dependencies": {
"@ice/bundles": "0.2.6",
"@ice/route-manifest": "1.2.2",
"@ice/runtime": "^1.4.5",
"@ice/shared-config": "1.2.6",
"@ice/webpack-config": "1.1.13",
"@ice/rspack-config": "1.1.6",
"@ice/runtime": "^1.4.7",
"@ice/shared-config": "1.2.7",
"@ice/webpack-config": "1.1.14",
"@ice/rspack-config": "1.1.7",
"@swc/helpers": "0.5.1",
"@types/express": "^4.17.14",
"address": "^1.1.2",
Expand Down
8 changes: 8 additions & 0 deletions packages/ice/src/bundler/config/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import ServerRunnerPlugin from '../../webpack/ServerRunnerPlugin.js';
import { IMPORT_META_RENDERER, IMPORT_META_TARGET, WEB } from '../../constant.js';
import getServerCompilerPlugin from '../../utils/getServerCompilerPlugin.js';
import ReCompilePlugin from '../../webpack/ReCompilePlugin.js';
import getEntryPoints from '../../utils/getEntryPoints.js';
import { multipleServerEntry } from '../../utils/multipleEntry.js';
import type ServerRunner from '../../service/ServerRunner';
import type ServerCompileTask from '../../utils/ServerCompileTask.js';
import type { ServerCompiler, UserConfig } from '../../types';
Expand All @@ -28,6 +30,8 @@ interface ServerPluginOptions {
serverEntry?: string;
ensureRoutesConfig: () => Promise<void>;
userConfig?: UserConfig;
getFlattenRoutes?: () => string[];
command?: string;
}
export const getServerPlugin = ({
serverRunner,
Expand All @@ -39,6 +43,8 @@ export const getServerPlugin = ({
outputDir,
serverCompileTask,
userConfig,
getFlattenRoutes,
command,
}: ServerPluginOptions) => {
if (serverRunner) {
return new ServerRunnerPlugin(serverRunner, ensureRoutesConfig);
Expand All @@ -51,6 +57,8 @@ export const getServerPlugin = ({
serverCompileTask,
userConfig,
ensureRoutesConfig,
entryPoints: multipleServerEntry(userConfig, command)
? getEntryPoints(rootDir, getFlattenRoutes(), serverEntry) : undefined,
runtimeDefineVars: {
[IMPORT_META_TARGET]: JSON.stringify(target),
[IMPORT_META_RENDERER]: JSON.stringify('server'),
Expand Down
15 changes: 14 additions & 1 deletion packages/ice/src/bundler/rspack/getConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import { getReCompilePlugin, getServerPlugin, getSpinnerPlugin } from '../config/plugins.js';
import { getExpandedEnvs } from '../../utils/runtimeEnv.js';
import type { BundlerOptions, Context } from '../types.js';
import type { PluginData } from '../../types/plugin.js';

type GetConfig = (
context: Context,
Expand All @@ -34,9 +35,11 @@ const getConfig: GetConfig = async (context, options, rspack) => {
const {
rootDir,
userConfig,
command,
extendsPluginAPI: {
serverCompileTask,
getRoutesFile,
getFlattenRoutes,
},
} = context;
const { reCompile, ensureRoutesConfig } = getRouteExportConfig(rootDir);
Expand All @@ -56,6 +59,8 @@ const getConfig: GetConfig = async (context, options, rspack) => {
outputDir,
serverCompileTask,
userConfig,
getFlattenRoutes,
command,
}),
// Add ReCompile plugin when routes config changed.
getReCompilePlugin(reCompile, routeManifest),
Expand Down Expand Up @@ -94,9 +99,17 @@ export const getDataLoaderConfig: GetDataLoaderRspackConfig = async (context, ta
extendsPluginAPI: {
generator,
},
getAllPlugin,
} = context;
const { config } = task;
const frameworkExports = generator.getExportList('framework', config.target);
const plugins = getAllPlugin(['keepExports']) as PluginData[];
let keepExports = ['dataLoader'];
plugins.forEach(plugin => {
if (plugin.keepExports) {
keepExports = keepExports.concat(plugin.keepExports);
}
});
return await getRspackConfig({
rootDir,
rspack,
Expand All @@ -115,7 +128,7 @@ export const getDataLoaderConfig: GetDataLoaderRspackConfig = async (context, ta
'data-loader': path.join(rootDir, RUNTIME_TMP_DIR, 'data-loader.ts'),
},
swcOptions: {
keepExports: ['dataLoader'],
keepExports,
},
splitChunks: false,
redirectImports: frameworkExports,
Expand Down
3 changes: 3 additions & 0 deletions packages/ice/src/bundler/webpack/getWebpackConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const getWebpackConfig: GetWebpackConfig = async (context, options) => {
configFilePath,
extendsPluginAPI: {
serverCompileTask,
getFlattenRoutes,
getRoutesFile,
generator,
},
Expand Down Expand Up @@ -96,6 +97,8 @@ const getWebpackConfig: GetWebpackConfig = async (context, options) => {
outputDir,
serverCompileTask,
userConfig,
command,
getFlattenRoutes,
});
if (serverCompilerPlugin) {
webpackConfig.plugins.push(serverCompilerPlugin);
Expand Down
25 changes: 22 additions & 3 deletions packages/ice/src/createService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import addPolyfills from './utils/runtimePolyfill.js';
import webpackBundler from './bundler/webpack/index.js';
import rspackBundler from './bundler/rspack/index.js';
import getDefaultTaskConfig from './plugins/task.js';
import { multipleServerEntry, renderMultiEntry } from './utils/multipleEntry.js';
import hasDocument from './utils/hasDocument.js';

const require = createRequire(import.meta.url);
Expand Down Expand Up @@ -93,8 +94,13 @@ async function createService({ rootDir, command, commandArgs }: CreateServiceOpt
addEntryCode: (callback: (originalCode: string) => string) => {
entryCode = callback(entryCode);
},
addEntryImportAhead: (declarationData: Pick<DeclarationData, 'source'>) => {
generator.addDeclaration('entry', declarationData);
addEntryImportAhead: (declarationData: Pick<DeclarationData, 'source'>, type = 'client') => {
if (type === 'both' || type === 'server') {
generator.addDeclaration('entryServer', declarationData);
}
if (type === 'both' || type === 'client') {
generator.addDeclaration('entry', declarationData);
}
},
modifyRenderData: generator.modifyRenderData,
addDataLoaderImport: (declarationData: DeclarationData) => {
Expand Down Expand Up @@ -243,7 +249,10 @@ async function createService({ rootDir, command, commandArgs }: CreateServiceOpt
const iceRuntimePath = '@ice/runtime';
// Only when code splitting use the default strategy or set to `router`, the router will be lazy loaded.
const lazy = [true, 'chunks', 'page', 'page-vendors'].includes(userConfig.codeSplitting);
const { routeImports, routeDefinition } = getRoutesDefinition(routesInfo.routes, lazy);
const { routeImports, routeDefinition } = getRoutesDefinition({
manifest: routesInfo.routes,
lazy,
});
const loaderExports = hasExportAppData || Boolean(routesInfo.loaders);
const hasDataLoader = Boolean(userConfig.dataLoader) && loaderExports;
// add render data
Expand All @@ -267,6 +276,7 @@ async function createService({ rootDir, command, commandArgs }: CreateServiceOpt
hasDataLoader,
routeImports,
routeDefinition,
routesFile: './routes',
});
dataCache.set('routes', JSON.stringify(routesInfo));
dataCache.set('hasExportAppData', hasExportAppData ? 'true' : '');
Expand Down Expand Up @@ -304,6 +314,15 @@ async function createService({ rootDir, command, commandArgs }: CreateServiceOpt
});
}

if (multipleServerEntry(userConfig, command)) {
renderMultiEntry({
generator,
renderRoutes: routeManifest.getFlattenRoute(),
routesManifest: routesInfo.routes,
lazy,
});
}

// render template before webpack compile
const renderStart = new Date().getTime();
generator.render();
Expand Down
5 changes: 4 additions & 1 deletion packages/ice/src/getWatchEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ const getWatchEvents = (options: Options): WatchEvent[] => {
async (eventName: string) => {
if (eventName === 'add' || eventName === 'unlink' || eventName === 'change') {
const routesRenderData = await generateRoutesInfo(rootDir, routesConfig);
const { routeImports, routeDefinition } = getRoutesDefinition(routesRenderData.routes, lazyRoutes);
const { routeImports, routeDefinition } = getRoutesDefinition({
manifest: routesRenderData.routes,
lazy: lazyRoutes,
});
const stringifiedData = JSON.stringify(routesRenderData);
if (cache.get('routes') !== stringifiedData) {
cache.set('routes', stringifiedData);
Expand Down
22 changes: 19 additions & 3 deletions packages/ice/src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,20 @@ function getFilePath(file: string) {
return formatPath(path.isAbsolute(file) ? file : `@/pages/${file}`.replace(new RegExp(`${path.extname(file)}$`), ''));
}

export function getRoutesDefinition(nestRouteManifest: NestedRouteManifest[], lazy = false, depth = 0) {
interface GetDefinationOptions {
manifest: NestedRouteManifest[];
lazy?: boolean;
depth?: number;
matchRoute?: (route: NestedRouteManifest) => boolean;
}

export function getRoutesDefinition(options: GetDefinationOptions) {
const { manifest, lazy = false, depth = 0, matchRoute = () => true } = options;
const routeImports: string[] = [];
const routeDefinition = nestRouteManifest.reduce((prev, route) => {
const routeDefinition = manifest.reduce((prev, route) => {
if (!matchRoute(route)) {
return prev;
}
const { children, path: routePath, index, componentName, file, id, layout, exports } = route;
const componentPath = id.startsWith('__') ? file : getFilePath(file);

Expand Down Expand Up @@ -112,7 +123,12 @@ export function getRoutesDefinition(nestRouteManifest: NestedRouteManifest[], la
routeProperties.push('layout: true,');
}
if (children) {
const res = getRoutesDefinition(children, lazy, depth + 1);
const res = getRoutesDefinition({
manifest: children,
lazy,
depth: depth + 1,
matchRoute,
});
routeImports.push(...res.routeImports);
routeProperties.push(`children: [${res.routeDefinition}]`);
}
Expand Down
Loading

0 comments on commit 280b290

Please sign in to comment.