diff --git a/examples/with-intl/.browserslistrc b/examples/with-intl/.browserslistrc
new file mode 100644
index 0000000000..7637baddc3
--- /dev/null
+++ b/examples/with-intl/.browserslistrc
@@ -0,0 +1 @@
+chrome 55
\ No newline at end of file
diff --git a/examples/with-intl/ice.config.mts b/examples/with-intl/ice.config.mts
new file mode 100644
index 0000000000..f721ecc97b
--- /dev/null
+++ b/examples/with-intl/ice.config.mts
@@ -0,0 +1,6 @@
+import { defineConfig } from '@ice/app';
+import intl from '@ice/plugin-intl';
+
+export default defineConfig(() => ({
+ plugins: [intl()],
+}));
diff --git a/examples/with-intl/package.json b/examples/with-intl/package.json
new file mode 100644
index 0000000000..b54a99d39a
--- /dev/null
+++ b/examples/with-intl/package.json
@@ -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"
+ }
+}
diff --git a/examples/with-intl/public/favicon.ico b/examples/with-intl/public/favicon.ico
new file mode 100644
index 0000000000..a2605c57e9
Binary files /dev/null and b/examples/with-intl/public/favicon.ico differ
diff --git a/examples/with-intl/src/app.tsx b/examples/with-intl/src/app.tsx
new file mode 100644
index 0000000000..b5373fa689
--- /dev/null
+++ b/examples/with-intl/src/app.tsx
@@ -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',
+};
diff --git a/examples/with-intl/src/document.tsx b/examples/with-intl/src/document.tsx
new file mode 100644
index 0000000000..1e7b99c49d
--- /dev/null
+++ b/examples/with-intl/src/document.tsx
@@ -0,0 +1,22 @@
+import { Meta, Title, Links, Main, Scripts } from 'ice';
+
+function Document() {
+ return (
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ );
+}
+
+export default Document;
diff --git a/examples/with-intl/src/global.css b/examples/with-intl/src/global.css
new file mode 100644
index 0000000000..604282adc9
--- /dev/null
+++ b/examples/with-intl/src/global.css
@@ -0,0 +1,3 @@
+body {
+ font-size: 14px;
+}
diff --git a/examples/with-intl/src/locales/en-US.ts b/examples/with-intl/src/locales/en-US.ts
new file mode 100644
index 0000000000..4e07843c44
--- /dev/null
+++ b/examples/with-intl/src/locales/en-US.ts
@@ -0,0 +1,3 @@
+export default {
+ new: 'New',
+};
diff --git a/examples/with-intl/src/locales/zh-CN.json b/examples/with-intl/src/locales/zh-CN.json
new file mode 100644
index 0000000000..05912a29f6
--- /dev/null
+++ b/examples/with-intl/src/locales/zh-CN.json
@@ -0,0 +1,3 @@
+{
+ "new": "新建"
+}
diff --git a/examples/with-intl/src/pages/index.tsx b/examples/with-intl/src/pages/index.tsx
new file mode 100644
index 0000000000..3d40c8df36
--- /dev/null
+++ b/examples/with-intl/src/pages/index.tsx
@@ -0,0 +1,10 @@
+import { intl } from 'ice';
+
+export default function Home() {
+ return (
+ <>
+ home
+
+ >
+ );
+}
diff --git a/examples/with-intl/src/typings.d.ts b/examples/with-intl/src/typings.d.ts
new file mode 100644
index 0000000000..1f6ba4ffa6
--- /dev/null
+++ b/examples/with-intl/src/typings.d.ts
@@ -0,0 +1 @@
+///
diff --git a/examples/with-intl/tsconfig.json b/examples/with-intl/tsconfig.json
new file mode 100644
index 0000000000..26fd9ec799
--- /dev/null
+++ b/examples/with-intl/tsconfig.json
@@ -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"]
+}
\ No newline at end of file
diff --git a/examples/with-request/src/app.tsx b/examples/with-request/src/app.tsx
index c95d85f2b6..a8c0f7a935 100644
--- a/examples/with-request/src/app.tsx
+++ b/examples/with-request/src/app.tsx
@@ -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) {
diff --git a/packages/ice/CHANGELOG.md b/packages/ice/CHANGELOG.md
index ace526e3b5..c96a5200af 100644
--- a/packages/ice/CHANGELOG.md
+++ b/packages/ice/CHANGELOG.md
@@ -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
diff --git a/packages/ice/package.json b/packages/ice/package.json
index 8177386229..d76fd776e5 100644
--- a/packages/ice/package.json
+++ b/packages/ice/package.json
@@ -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",
@@ -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",
diff --git a/packages/ice/src/bundler/config/plugins.ts b/packages/ice/src/bundler/config/plugins.ts
index f2ce39d9f9..a17f5410a3 100644
--- a/packages/ice/src/bundler/config/plugins.ts
+++ b/packages/ice/src/bundler/config/plugins.ts
@@ -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';
@@ -28,6 +30,8 @@ interface ServerPluginOptions {
serverEntry?: string;
ensureRoutesConfig: () => Promise;
userConfig?: UserConfig;
+ getFlattenRoutes?: () => string[];
+ command?: string;
}
export const getServerPlugin = ({
serverRunner,
@@ -39,6 +43,8 @@ export const getServerPlugin = ({
outputDir,
serverCompileTask,
userConfig,
+ getFlattenRoutes,
+ command,
}: ServerPluginOptions) => {
if (serverRunner) {
return new ServerRunnerPlugin(serverRunner, ensureRoutesConfig);
@@ -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'),
diff --git a/packages/ice/src/bundler/rspack/getConfig.ts b/packages/ice/src/bundler/rspack/getConfig.ts
index 955f9a5b0d..1ca8a848b5 100644
--- a/packages/ice/src/bundler/rspack/getConfig.ts
+++ b/packages/ice/src/bundler/rspack/getConfig.ts
@@ -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,
@@ -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);
@@ -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),
@@ -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,
@@ -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,
diff --git a/packages/ice/src/bundler/webpack/getWebpackConfig.ts b/packages/ice/src/bundler/webpack/getWebpackConfig.ts
index d45402f19d..c086f9c4b6 100644
--- a/packages/ice/src/bundler/webpack/getWebpackConfig.ts
+++ b/packages/ice/src/bundler/webpack/getWebpackConfig.ts
@@ -59,6 +59,7 @@ const getWebpackConfig: GetWebpackConfig = async (context, options) => {
configFilePath,
extendsPluginAPI: {
serverCompileTask,
+ getFlattenRoutes,
getRoutesFile,
generator,
},
@@ -96,6 +97,8 @@ const getWebpackConfig: GetWebpackConfig = async (context, options) => {
outputDir,
serverCompileTask,
userConfig,
+ command,
+ getFlattenRoutes,
});
if (serverCompilerPlugin) {
webpackConfig.plugins.push(serverCompilerPlugin);
diff --git a/packages/ice/src/createService.ts b/packages/ice/src/createService.ts
index b440de2976..a20bbb27ee 100644
--- a/packages/ice/src/createService.ts
+++ b/packages/ice/src/createService.ts
@@ -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);
@@ -93,8 +94,13 @@ async function createService({ rootDir, command, commandArgs }: CreateServiceOpt
addEntryCode: (callback: (originalCode: string) => string) => {
entryCode = callback(entryCode);
},
- addEntryImportAhead: (declarationData: Pick) => {
- generator.addDeclaration('entry', declarationData);
+ addEntryImportAhead: (declarationData: Pick, 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) => {
@@ -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
@@ -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' : '');
@@ -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();
diff --git a/packages/ice/src/getWatchEvents.ts b/packages/ice/src/getWatchEvents.ts
index 05eda45a47..ec697bccfe 100644
--- a/packages/ice/src/getWatchEvents.ts
+++ b/packages/ice/src/getWatchEvents.ts
@@ -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);
diff --git a/packages/ice/src/routes.ts b/packages/ice/src/routes.ts
index bfe542376c..f841fbab50 100644
--- a/packages/ice/src/routes.ts
+++ b/packages/ice/src/routes.ts
@@ -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);
@@ -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}]`);
}
diff --git a/packages/ice/src/service/runtimeGenerator.ts b/packages/ice/src/service/runtimeGenerator.ts
index d9c39cb070..e115b1bb11 100644
--- a/packages/ice/src/service/runtimeGenerator.ts
+++ b/packages/ice/src/service/runtimeGenerator.ts
@@ -141,7 +141,7 @@ export default class Generator {
this.rerender = false;
this.renderTemplates = [];
this.renderDataRegistration = [];
- this.contentTypes = ['framework', 'frameworkTypes', 'routeConfigTypes', 'dataLoaderImport', 'runtimeOptions', 'entry'];
+ this.contentTypes = ['framework', 'frameworkTypes', 'routeConfigTypes', 'dataLoaderImport', 'runtimeOptions', 'entry', 'entryServer'];
// empty .ice before render
fse.emptyDirSync(path.join(rootDir, targetDir));
// add initial templates
diff --git a/packages/ice/src/types/plugin.ts b/packages/ice/src/types/plugin.ts
index cd19b013f2..7043b36ad2 100644
--- a/packages/ice/src/types/plugin.ts
+++ b/packages/ice/src/types/plugin.ts
@@ -13,7 +13,7 @@ export type { CreateLoggerReturnType } from '../utils/logger.js';
type AddExport = (exportData: DeclarationData) => void;
type AddEntryCode = (callback: (code: string) => string) => void;
-type AddEntryImportAhead = (exportData: Pick) => void;
+type AddEntryImportAhead = (exportData: Pick, type?: string) => void;
type RemoveExport = (removeSource: string | string[]) => void;
type EventName = 'add' | 'addDir' | 'change' | 'unlink' | 'unlinkDir';
type GetExportList = (key: string, target?: string) => DeclarationData[];
diff --git a/packages/ice/src/types/userConfig.ts b/packages/ice/src/types/userConfig.ts
index f924fdc789..ae252c00a9 100644
--- a/packages/ice/src/types/userConfig.ts
+++ b/packages/ice/src/types/userConfig.ts
@@ -220,7 +220,7 @@ export interface UserConfig {
/**
* bundle server code as a single file
*/
- bundle?: boolean;
+ bundle?: boolean | 'page';
/**
* ignore file when bundle server code, module return empty when match
*/
diff --git a/packages/ice/src/utils/generateEntry.ts b/packages/ice/src/utils/generateEntry.ts
index 20c8743909..198e59d8c1 100644
--- a/packages/ice/src/utils/generateEntry.ts
+++ b/packages/ice/src/utils/generateEntry.ts
@@ -67,9 +67,13 @@ const writeFile = async (file: string, content: string) => {
await fse.writeFile(file, content);
};
-function formatFilePath(routePath: string, type: 'js' | 'html' | 'js.map'): string {
+export function escapeRoutePath(str: string) {
// Win32 do not support file name start with ':' and '*'.
- return routePath === '/' ? `index.${type}` : `${routePath.replace(/\/(:|\*)/g, '/$')}.${type}`;
+ return str.replace(/\/(:|\*)/g, '/$');
+}
+
+function formatFilePath(routePath: string, type: 'js' | 'html' | 'js.map'): string {
+ return routePath === '/' ? `index.${type}` : `${escapeRoutePath(routePath)}.${type}`;
}
async function generateFilePath(
diff --git a/packages/ice/src/utils/getEntryPoints.ts b/packages/ice/src/utils/getEntryPoints.ts
new file mode 100644
index 0000000000..94e6c78c27
--- /dev/null
+++ b/packages/ice/src/utils/getEntryPoints.ts
@@ -0,0 +1,17 @@
+import * as path from 'path';
+import { RUNTIME_TMP_DIR } from '../constant.js';
+import getServerEntry from './getServerEntry.js';
+import { formatServerEntry } from './multipleEntry.js';
+
+function getEntryPoints(rootDir: string, routes: string[], mainEntry: string) {
+ const serverEntry: Record = {};
+ routes.forEach((route) => {
+ serverEntry[`pages${route === '/' ? '/index' : route}`] =
+ path.join(rootDir, RUNTIME_TMP_DIR, formatServerEntry(route));
+ });
+ serverEntry.index = getServerEntry(rootDir, mainEntry);
+
+ return serverEntry;
+}
+
+export default getEntryPoints;
diff --git a/packages/ice/src/utils/getServerCompilerPlugin.ts b/packages/ice/src/utils/getServerCompilerPlugin.ts
index ecddd9eb85..a4f3db2fa1 100644
--- a/packages/ice/src/utils/getServerCompilerPlugin.ts
+++ b/packages/ice/src/utils/getServerCompilerPlugin.ts
@@ -13,6 +13,7 @@ interface Options {
serverCompileTask: ExtendsPluginAPI['serverCompileTask'];
ensureRoutesConfig: () => Promise;
runtimeDefineVars: Record;
+ entryPoints?: Record;
}
function getServerCompilerPlugin(serverCompiler: ServerCompiler, options: Options) {
@@ -24,15 +25,16 @@ function getServerCompilerPlugin(serverCompiler: ServerCompiler, options: Option
serverCompileTask,
ensureRoutesConfig,
runtimeDefineVars,
+ entryPoints,
} = options;
- const entryPoint = getServerEntry(rootDir, serverEntry);
const { ssg, ssr, server: { format } } = userConfig;
const isEsm = userConfig?.server?.format === 'esm';
+
return new ServerCompilerPlugin(
serverCompiler,
[
{
- entryPoints: { index: entryPoint },
+ entryPoints: entryPoints || { index: getServerEntry(rootDir, serverEntry) },
outdir: path.join(outputDir, SERVER_OUTPUT_DIR),
splitting: isEsm,
format,
diff --git a/packages/ice/src/utils/multipleEntry.ts b/packages/ice/src/utils/multipleEntry.ts
new file mode 100644
index 0000000000..31b7ce631d
--- /dev/null
+++ b/packages/ice/src/utils/multipleEntry.ts
@@ -0,0 +1,56 @@
+import matchRoutes from '@ice/runtime/matchRoutes';
+import type { NestedRouteManifest } from '@ice/route-manifest';
+import type { CommandName } from 'build-scripts';
+import { getRoutesDefinition } from '../routes.js';
+import type Generator from '../service/runtimeGenerator.js';
+import type { UserConfig } from '../types/userConfig.js';
+import { escapeRoutePath } from './generateEntry.js';
+
+interface Options {
+ renderRoutes: string[];
+ routesManifest: NestedRouteManifest[];
+ generator: Generator;
+ lazy: boolean;
+}
+
+export const multipleServerEntry = (userConfig: UserConfig, command: CommandName): boolean => {
+ return userConfig?.server?.bundle === 'page' &&
+ userConfig.server.format === 'cjs' &&
+ command === 'build';
+};
+
+export const formatRoutePath = (route: string) => {
+ return escapeRoutePath(route)
+ .replace(/^\//, '').replace(/\//g, '_');
+};
+
+export const formatServerEntry = (route: string) => {
+ return `server.entry.${formatRoutePath(route) || 'index'}.ts`;
+};
+
+export function renderMultiEntry(options: Options) {
+ const { renderRoutes, routesManifest, generator, lazy } = options;
+ renderRoutes.forEach((route) => {
+ const routeId = formatRoutePath(route);
+ generator.addRenderFile(
+ 'core/entry.server.ts.ejs',
+ formatServerEntry(route),
+ {
+ routesFile: `./routes.${routeId}`,
+ },
+ );
+ // Generate route file for each route.
+ const matches = matchRoutes(routesManifest, route);
+ const { routeImports, routeDefinition } = getRoutesDefinition({
+ manifest: routesManifest,
+ lazy,
+ matchRoute: (routeItem) => {
+ return matches.some((match) => match.route.id === routeItem.id);
+ },
+ });
+ generator.addRenderFile('core/routes.tsx.ejs', `routes.${routeId}.tsx`, {
+ routeImports,
+ routeDefinition,
+ });
+ });
+}
diff --git a/packages/ice/templates/core/entry.server.ts.ejs b/packages/ice/templates/core/entry.server.ts.ejs
index eb62643ce8..c4ae2cfe13 100644
--- a/packages/ice/templates/core/entry.server.ts.ejs
+++ b/packages/ice/templates/core/entry.server.ts.ejs
@@ -1,4 +1,5 @@
import './env.server';
+<%- entryServer.imports %>
import * as runtime from '@ice/runtime/server';
<% if (hydrate) {-%>
import { commons, statics } from './runtime-modules';
@@ -14,13 +15,14 @@ import type { RenderToPipeableStreamOptions } from 'react-dom/server';
// @ts-ignore
import assetsManifest from 'virtual:assets-manifest.json';
<% if (hydrate) {-%>
-import createRoutes from './routes';
+import createRoutes from '<%- routesFile %>';
<% } else { -%>
import routesManifest from './route-manifest.json';
<% } -%>
import routesConfig from './routes-config.bundle.mjs';
<% if (dataLoaderImport.imports) {-%><%-dataLoaderImport.imports%><% } -%>
<% if (hydrate) {-%><%- runtimeOptions.imports %><% } -%>
+
<% if (!hydrate) {-%>
// Do not inject runtime modules when render mode is document only.
const commons = [];
diff --git a/packages/plugin-i18n/package.json b/packages/plugin-i18n/package.json
index bcabba8076..d75adf7de2 100644
--- a/packages/plugin-i18n/package.json
+++ b/packages/plugin-i18n/package.json
@@ -56,8 +56,8 @@
"webpack-dev-server": "4.15.0"
},
"peerDependencies": {
- "@ice/app": "^3.4.7",
- "@ice/runtime": "^1.4.5"
+ "@ice/app": "^3.4.8",
+ "@ice/runtime": "^1.4.7"
},
"publishConfig": {
"access": "public"
diff --git a/packages/plugin-intl/CHANGELOG.md b/packages/plugin-intl/CHANGELOG.md
new file mode 100644
index 0000000000..7e9ae42333
--- /dev/null
+++ b/packages/plugin-intl/CHANGELOG.md
@@ -0,0 +1,5 @@
+# @ice/plugin-intl
+
+## 1.0.0
+
+- Initial release
diff --git a/packages/plugin-intl/README.md b/packages/plugin-intl/README.md
new file mode 100644
index 0000000000..ba9e5ea78e
--- /dev/null
+++ b/packages/plugin-intl/README.md
@@ -0,0 +1,73 @@
+# @ice/plugin-intl
+
+`@ice/plugin-intl` is a ice.js plugin. It provides a simple way to add internationalization support to your application.
+
+> `@ice/plugin-intl` is based on `react-intl`.
+
+## Install
+
+```bash
+$ npm i @ice/plugin-intl --save-dev
+```
+
+## Usage
+
+Define the plugin in `ice.config.mts`:
+
+```ts
+import { defineConfig } from '@ice/app';
+import intl from '@ice/plugin-intl';
+
+export default defineConfig({
+ plugins: [
+ intl(),
+ ],
+});
+```
+
+Define locale config in `src/app.ts`:
+
+```ts
+import { defineAppConfig } from 'ice';
+import type { LocaleConfig } from '@ice/plugin-intl/types';
+
+export default defineAppConfig(() => ({}));
+
+export const locale: LocaleConfig = {
+ // Cutomize getLocale method and other options supported by react-intl.
+ getLocale: () => 'en-US',
+};
+```
+
+## Locales
+
+Locales are defined in the `src/locales` directory. Each locale is defined in a separate file, with the locale name as the file name. For example, `en-US.ts`:
+
+```ts
+export default {
+ 'app.title': 'My Application',
+ 'app.welcome': 'Welcome to my application!',
+};
+```
+
+Use the `useIntl` hook to access the current locale:
+
+```tsx
+import { useIntl } from 'ice';
+
+export default function Home() {
+ const intl = useIntl();
+ console.log(intl.formatMessage({ id: 'new' }));
+ return home
;
+}
+```
+
+Use the `intl` function to access the current locale:
+
+```tsx
+import { intl } from 'ice';
+
+function alertMessage() {
+ alert(intl.formatMessage({ id: 'app.welcome' }));
+}
+```
diff --git a/packages/plugin-intl/package.json b/packages/plugin-intl/package.json
new file mode 100644
index 0000000000..f1747c4af1
--- /dev/null
+++ b/packages/plugin-intl/package.json
@@ -0,0 +1,42 @@
+{
+ "name": "@ice/plugin-intl",
+ "version": "1.0.0",
+ "description": "react intl plugin for ice.js 3.",
+ "files": [
+ "esm",
+ "!esm/**/*.map",
+ "*.d.ts",
+ "templates"
+ ],
+ "type": "module",
+ "main": "esm/index.js",
+ "module": "esm/index.js",
+ "types": "esm/index.d.ts",
+ "exports": {
+ ".": "./esm/index.js",
+ "./runtime": "./esm/runtime.js",
+ "./types": "./esm/types.js"
+ },
+ "sideEffects": false,
+ "scripts": {
+ "watch": "tsc -w --sourceMap",
+ "build": "tsc"
+ },
+ "dependencies": {
+ "react-intl": "^6.0.0",
+ "fast-glob": "^3.3.2"
+ },
+ "devDependencies": {
+ "@ice/app": "^3.3.2",
+ "@ice/runtime": "^1.2.9",
+ "@types/react": "^18.0.0",
+ "@types/react-dom": "^18.0.0"
+ },
+ "repository": {
+ "type": "http",
+ "url": "https://github.com/alibaba/ice/tree/master/packages/plugin-intl"
+ },
+ "publishConfig": {
+ "access": "public"
+ }
+}
diff --git a/packages/plugin-intl/runtime.d.ts b/packages/plugin-intl/runtime.d.ts
new file mode 100644
index 0000000000..72417e24df
--- /dev/null
+++ b/packages/plugin-intl/runtime.d.ts
@@ -0,0 +1 @@
+export * from './esm/runtime';
diff --git a/packages/plugin-intl/src/index.ts b/packages/plugin-intl/src/index.ts
new file mode 100644
index 0000000000..5a18d5a28f
--- /dev/null
+++ b/packages/plugin-intl/src/index.ts
@@ -0,0 +1,74 @@
+import * as path from 'path';
+import { fileURLToPath } from 'url';
+import fg from 'fast-glob';
+import type { Plugin } from '@ice/app/types';
+
+const _dirname = path.dirname(fileURLToPath(import.meta.url));
+
+const plugin: Plugin = () => ({
+ name: 'plugin-intl',
+ setup: ({ generator, context, createLogger, watch }) => {
+ const { rootDir } = context;
+ const logger = createLogger('plugin-intl');
+
+ const renderLocaleEntry = (localeFiles: string[]) => {
+ const locales = [];
+ let localeExport = [];
+ localeFiles.forEach((file) => {
+ const filename = path.basename(file, path.extname(file));
+ // `-` is not allowed in import specifier.
+ const specifier = filename.replace('-', '_');
+ locales.push(`import ${specifier} from '@/locales/${filename}';`);
+ localeExport.push(`'${filename}': ${specifier},`);
+ });
+
+ generator.addRenderFile(
+ path.join(_dirname, '../templates/locales.ts.ejs'),
+ 'locales.ts',
+ {
+ localeImport: locales.join('\n'),
+ localeExport: localeExport.join('\n '),
+ },
+ );
+ };
+ const globRule = 'src/locales/*.{ts,js,json}';
+ // Glob all locale files, and generate runtime options.
+ const localeFiles = fg.sync(globRule, { cwd: rootDir });
+ if (localeFiles.length > 0) {
+ // Filter the entry of locale files.
+ const mainEntry = localeFiles.find((file) => file.match(/index\.(ts|js|json)$/));
+ let runtimeSource = '';
+ if (mainEntry) {
+ runtimeSource = `@/locales/${path.basename(mainEntry)}`;
+ } else {
+ // Create a locale entry file to export all locale files.
+ renderLocaleEntry(localeFiles);
+
+ // Add watch event for locale files added or removed.
+ watch.addEvent([/src\/locales/, (event) => {
+ if (event === 'unlink' || event === 'add') {
+ const files = fg.sync(globRule, { cwd: rootDir });
+ renderLocaleEntry(files);
+ }
+ }]);
+ runtimeSource = './locales';
+
+ generator.addEntryImportAhead({
+ source: runtimeSource,
+ // @ts-ignore
+ }, 'both');
+ }
+ } else {
+ logger.warn('No locale files found, please check the `src/locales` folder.');
+ }
+
+ // Add intl export from ice.
+ generator.addExport({
+ specifier: ['useIntl', 'intl'],
+ source: '@ice/plugin-intl/runtime',
+ });
+ },
+ runtime: '@ice/plugin-intl/runtime',
+});
+
+export default plugin;
diff --git a/packages/plugin-intl/src/runtime.tsx b/packages/plugin-intl/src/runtime.tsx
new file mode 100644
index 0000000000..60d91400e9
--- /dev/null
+++ b/packages/plugin-intl/src/runtime.tsx
@@ -0,0 +1,51 @@
+import * as React from 'react';
+import { createIntl, createIntlCache, RawIntlProvider, useIntl } from 'react-intl';
+import type { IntlShape } from 'react-intl';
+import type { RuntimePlugin } from '@ice/runtime/types';
+import type { LocaleConfig } from './types.js';
+
+const EXPORT_NAME = 'locale';
+const cache = createIntlCache();
+
+const getDefaultLocale = () => {
+ return (typeof navigator !== 'undefined' && navigator.language) || 'zh-CN';
+};
+
+const getLocaleMessages = () => {
+ // @ts-ignore
+ const localeMessages = typeof window === 'undefined' ? global.__ICE_LOCALE_MESSAGES__ : window.__ICE_LOCALE_MESSAGES__;
+ return localeMessages || {};
+};
+
+const defaultLocale = getDefaultLocale();
+let intl: IntlShape = createIntl({
+ locale: defaultLocale,
+ messages: getLocaleMessages()?.[defaultLocale] || {},
+});
+
+const runtime: RuntimePlugin = async ({
+ addProvider,
+ appContext,
+}) => {
+ const { appExport } = appContext;
+ const exported = appExport[EXPORT_NAME];
+ const localeConfig: LocaleConfig = (typeof exported === 'function' ? await exported() : exported) || {};
+ const { getLocale, ...l } = localeConfig;
+ const locale = getLocale ? getLocale() : getDefaultLocale();
+
+ intl = createIntl({
+ ...l,
+ messages: getLocaleMessages()?.[locale] || {},
+ locale: getLocale ? getLocale() : getDefaultLocale(),
+ }, cache);
+ addProvider(({ children }) => {
+ return {children};
+ });
+};
+
+export {
+ intl,
+ useIntl,
+};
+
+export default runtime;
diff --git a/packages/plugin-intl/src/types.ts b/packages/plugin-intl/src/types.ts
new file mode 100644
index 0000000000..57f058e32c
--- /dev/null
+++ b/packages/plugin-intl/src/types.ts
@@ -0,0 +1,7 @@
+import type { IntlConfig } from 'react-intl';
+
+interface AdditionalConfig {
+ getLocale: () => string;
+}
+
+export type LocaleConfig = Partial & AdditionalConfig;
diff --git a/packages/plugin-intl/templates/locales.ts.ejs b/packages/plugin-intl/templates/locales.ts.ejs
new file mode 100644
index 0000000000..d75f402aa6
--- /dev/null
+++ b/packages/plugin-intl/templates/locales.ts.ejs
@@ -0,0 +1,13 @@
+<%- localeImport %>
+
+const localeMessages = {
+ <%- localeExport %>
+};
+const LOCALE_KEY = '__ICE_LOCALE_MESSAGES__';
+if (typeof window !== 'undefined') {
+ window[LOCALE_KEY] = localeMessages;
+} else {
+ global[LOCALE_KEY]= localeMessages;
+}
+
+export default localeMessages;
diff --git a/packages/plugin-intl/tsconfig.json b/packages/plugin-intl/tsconfig.json
new file mode 100644
index 0000000000..ea83b793fe
--- /dev/null
+++ b/packages/plugin-intl/tsconfig.json
@@ -0,0 +1,11 @@
+{
+ "extends": "../../tsconfig.base.json",
+ "compilerOptions": {
+ "baseUrl": "./",
+ "rootDir": "src",
+ "outDir": "esm",
+ "module": "ES2020",
+ "moduleResolution": "NodeNext",
+ },
+ "include": ["src"]
+}
\ No newline at end of file
diff --git a/packages/plugin-intl/types.d.ts b/packages/plugin-intl/types.d.ts
new file mode 100644
index 0000000000..8554e6cd41
--- /dev/null
+++ b/packages/plugin-intl/types.d.ts
@@ -0,0 +1 @@
+export * from './esm/types';
diff --git a/packages/plugin-rax-compat/CHANGELOG.md b/packages/plugin-rax-compat/CHANGELOG.md
index 992f7107bd..493bbfd99c 100644
--- a/packages/plugin-rax-compat/CHANGELOG.md
+++ b/packages/plugin-rax-compat/CHANGELOG.md
@@ -1,5 +1,11 @@
# Changelog
+## 0.3.1
+
+### Patch Changes
+
+- e4a32686: fix: support pass options for `compilationConfig`
+
## 0.3.0
### Minor Changes
diff --git a/packages/plugin-rax-compat/package.json b/packages/plugin-rax-compat/package.json
index cb7ca6e94a..b624c28411 100644
--- a/packages/plugin-rax-compat/package.json
+++ b/packages/plugin-rax-compat/package.json
@@ -1,6 +1,6 @@
{
"name": "@ice/plugin-rax-compat",
- "version": "0.3.0",
+ "version": "0.3.1",
"description": "Provide rax compat support for ice.js",
"license": "MIT",
"type": "module",
@@ -30,7 +30,7 @@
"stylesheet-loader": "^0.9.1"
},
"devDependencies": {
- "@ice/app": "^3.4.2",
+ "@ice/app": "^3.4.8",
"@types/lodash-es": "^4.17.7",
"webpack": "^5.88.0"
},
diff --git a/packages/plugin-rax-compat/src/services/jsx.ts b/packages/plugin-rax-compat/src/services/jsx.ts
index 5c73818940..9bf15f7098 100644
--- a/packages/plugin-rax-compat/src/services/jsx.ts
+++ b/packages/plugin-rax-compat/src/services/jsx.ts
@@ -16,7 +16,7 @@ export class JSXService {
// Reset jsc.transform.react.runtime to classic.
config.swcOptions = merge(config.swcOptions || {}, {
- compilationConfig: (source: string, id: string) => {
+ compilationConfig: (source: string, id: string, compileOptions) => {
let swcCompilationConfig = {};
const hasJSXComment = source.indexOf('@jsx createElement') !== -1;
const isRaxComponent = /(from|require\()\s*['"]rax['"]/.test(source);
@@ -43,7 +43,7 @@ export class JSXService {
};
}
- return merge({}, originalSwcCompilationConfigFunc(source, id), swcCompilationConfig);
+ return merge({}, originalSwcCompilationConfigFunc(source, id, compileOptions), swcCompilationConfig);
},
});
});
diff --git a/packages/rspack-config/CHANGELOG.md b/packages/rspack-config/CHANGELOG.md
index 2a1b0a8dfe..1a080b497d 100644
--- a/packages/rspack-config/CHANGELOG.md
+++ b/packages/rspack-config/CHANGELOG.md
@@ -1,5 +1,13 @@
# @ice/rspack-config
+## 1.1.7
+
+### Patch Changes
+
+- e858a522: fix: support cli option `https` for speedup mode
+- Updated dependencies [e4a32686]
+ - @ice/shared-config@1.2.7
+
## 1.1.6
### Patch Changes
diff --git a/packages/rspack-config/package.json b/packages/rspack-config/package.json
index ade042ed32..aa27d49a95 100644
--- a/packages/rspack-config/package.json
+++ b/packages/rspack-config/package.json
@@ -1,6 +1,6 @@
{
"name": "@ice/rspack-config",
- "version": "1.1.6",
+ "version": "1.1.7",
"repository": "alibaba/ice",
"bugs": "https://github.com/alibaba/ice/issues",
"homepage": "https://v3.ice.work",
@@ -16,7 +16,7 @@
],
"dependencies": {
"@ice/bundles": "0.2.6",
- "@ice/shared-config": "1.2.6"
+ "@ice/shared-config": "1.2.7"
},
"devDependencies": {
"@rspack/core": "0.5.7"
diff --git a/packages/rspack-config/src/index.ts b/packages/rspack-config/src/index.ts
index 84e474a60c..205a3441dd 100644
--- a/packages/rspack-config/src/index.ts
+++ b/packages/rspack-config/src/index.ts
@@ -108,6 +108,7 @@ const getConfig: GetConfig = async (options) => {
redirectImports,
fastRefresh,
sourceMap,
+ https,
} = taskConfig || {};
const isDev = mode === 'development';
const absoluteOutputDir = path.isAbsolute(outputDir) ? outputDir : path.join(rootDir, outputDir);
@@ -306,6 +307,7 @@ const getConfig: GetConfig = async (options) => {
client: {
logging: 'info',
},
+ https,
...devServer,
setupMiddlewares: middlewares,
},
diff --git a/packages/runtime/CHANGELOG.md b/packages/runtime/CHANGELOG.md
index 91b5c19128..8e2bb7eefb 100644
--- a/packages/runtime/CHANGELOG.md
+++ b/packages/runtime/CHANGELOG.md
@@ -1,5 +1,11 @@
# @ice/runtime
+## 1.4.7
+
+### Patch Changes
+
+- e78c7d22: fix: single route mismatch warning for development
+
## 1.4.6
- Fix: serverDataLoader is not work when dataLoader is not defined.
diff --git a/packages/runtime/package.json b/packages/runtime/package.json
index fc33762574..cc3630f5a2 100644
--- a/packages/runtime/package.json
+++ b/packages/runtime/package.json
@@ -1,6 +1,6 @@
{
"name": "@ice/runtime",
- "version": "1.4.6",
+ "version": "1.4.7",
"description": "Runtime module for ice.js",
"type": "module",
"types": "./esm/index.d.ts",
diff --git a/packages/runtime/src/singleRouter.tsx b/packages/runtime/src/singleRouter.tsx
index 6d6a347244..2a65cd10e5 100644
--- a/packages/runtime/src/singleRouter.tsx
+++ b/packages/runtime/src/singleRouter.tsx
@@ -279,6 +279,10 @@ export const matchRoutes = (
for (let i = 0; matches == null && i < branches.length; i++) {
matches = matchRouteBranch(branches[i], stripedPathname);
}
+ if (!matches) {
+ console.warn('Single route manifest: ', routes);
+ console.warn(`Basename "${basename}" is not match with pathname "${pathname}"`);
+ }
return matches;
};
@@ -316,13 +320,13 @@ export const getSingleRoute = async (
let loaders = [];
let loaderIds = [];
const components = matchedRoutes.map(({ route }) => {
- const { loader } = routeModules[route.id];
+ const { loader, Component } = routeModules?.[route.id] || {};
if (loader) {
loaders.push(loader());
loaderIds.push(route.id);
}
return {
- Component: routeModules[route.id].Component || route.Component,
+ Component: Component || route.Component,
isDataRoute: !!loader,
id: route.id,
};
diff --git a/packages/shared-config/CHANGELOG.md b/packages/shared-config/CHANGELOG.md
index 49dcc30e88..49f03bfb4b 100644
--- a/packages/shared-config/CHANGELOG.md
+++ b/packages/shared-config/CHANGELOG.md
@@ -1,5 +1,11 @@
# @ice/shared-config
+## 1.2.7
+
+### Patch Changes
+
+- e4a32686: feat: support options for compilationConfig
+
## 1.2.6
### Patch Changes
diff --git a/packages/shared-config/package.json b/packages/shared-config/package.json
index ee34fb0b2e..0193fd6987 100644
--- a/packages/shared-config/package.json
+++ b/packages/shared-config/package.json
@@ -1,6 +1,6 @@
{
"name": "@ice/shared-config",
- "version": "1.2.6",
+ "version": "1.2.7",
"repository": "alibaba/ice",
"bugs": "https://github.com/alibaba/ice/issues",
"homepage": "https://v3.ice.work",
diff --git a/packages/shared-config/src/types.ts b/packages/shared-config/src/types.ts
index e284ab9038..91babe7ed8 100644
--- a/packages/shared-config/src/types.ts
+++ b/packages/shared-config/src/types.ts
@@ -40,9 +40,21 @@ interface ConfigurationCtx extends Config {
}
type Experimental = Configuration['experiments'];
+
+export type JSXSuffix = 'jsx' | 'tsx';
+export interface GetJsxTransformOptions {
+ rootDir: string;
+ mode: Options['mode'];
+ suffix?: JSXSuffix;
+ fastRefresh: boolean;
+ polyfill: Config['polyfill'];
+ enableEnv: boolean;
+}
+
interface SwcOptions {
removeExportExprs?: string[];
- compilationConfig?: SwcCompilationConfig | ((source: string, id: string) => SwcCompilationConfig);
+ compilationConfig?: SwcCompilationConfig |
+ ((source: string, id: string, options: GetJsxTransformOptions) => SwcCompilationConfig);
keepExports?: string[] | { value: string[]; include?: (id: string) => boolean };
nodeTransform?: boolean;
}
diff --git a/packages/shared-config/src/unPlugins/compilation.ts b/packages/shared-config/src/unPlugins/compilation.ts
index 7b25415cea..f847784228 100644
--- a/packages/shared-config/src/unPlugins/compilation.ts
+++ b/packages/shared-config/src/unPlugins/compilation.ts
@@ -5,13 +5,11 @@ import consola from 'consola';
import type { SwcConfig, ReactConfig } from '@ice/bundles';
import type { UnpluginOptions } from '@ice/bundles/compiled/unplugin/index.js';
import lodash from '@ice/bundles/compiled/lodash/index.js';
-import type { Config } from '../types.js';
+import type { Config, JSXSuffix, GetJsxTransformOptions } from '../types.js';
import transformImport from '../utils/transformImport.js';
const { merge } = lodash;
-type JSXSuffix = 'jsx' | 'tsx';
-
interface Options {
rootDir: string;
mode: 'development' | 'production' | 'none';
@@ -84,8 +82,8 @@ const compilationPlugin = (options: Options): UnpluginOptions => {
filename: id,
sourceMaps: !!sourceMap,
};
-
- const commonOptions = getJsxTransformOptions({ rootDir, mode, suffix, fastRefresh, polyfill, enableEnv });
+ const compileOptions = { rootDir, mode, suffix, fastRefresh, polyfill, enableEnv };
+ const commonOptions = getJsxTransformOptions(compileOptions);
// auto detect development mode
if (
@@ -99,7 +97,7 @@ const compilationPlugin = (options: Options): UnpluginOptions => {
merge(programmaticOptions, commonOptions);
if (typeof compilationConfig === 'function') {
- merge(programmaticOptions, compilationConfig(source, fileId));
+ merge(programmaticOptions, compilationConfig(source, fileId, compileOptions));
} else if (compilationConfig) {
merge(programmaticOptions, compilationConfig);
}
@@ -180,14 +178,6 @@ const compilationPlugin = (options: Options): UnpluginOptions => {
};
};
-interface GetJsxTransformOptions {
- rootDir: string;
- mode: Options['mode'];
- suffix?: JSXSuffix;
- fastRefresh: boolean;
- polyfill: Config['polyfill'];
- enableEnv: boolean;
-}
export function getJsxTransformOptions({
suffix,
diff --git a/packages/webpack-config/CHANGELOG.md b/packages/webpack-config/CHANGELOG.md
index 58e36ee7fd..0e726af0bb 100644
--- a/packages/webpack-config/CHANGELOG.md
+++ b/packages/webpack-config/CHANGELOG.md
@@ -1,5 +1,13 @@
# Changelog
+## 1.1.14
+
+### Patch Changes
+
+- a805fa95: fix: minify config of swc
+- Updated dependencies [e4a32686]
+ - @ice/shared-config@1.2.7
+
## 1.1.13
### Patch Changes
diff --git a/packages/webpack-config/package.json b/packages/webpack-config/package.json
index 8edae22d73..7f62579f6e 100644
--- a/packages/webpack-config/package.json
+++ b/packages/webpack-config/package.json
@@ -1,6 +1,6 @@
{
"name": "@ice/webpack-config",
- "version": "1.1.13",
+ "version": "1.1.14",
"repository": "alibaba/ice",
"bugs": "https://github.com/alibaba/ice/issues",
"homepage": "https://v3.ice.work",
@@ -15,7 +15,7 @@
"*.d.ts"
],
"dependencies": {
- "@ice/shared-config": "1.2.6",
+ "@ice/shared-config": "1.2.7",
"@ice/bundles": "0.2.6",
"fast-glob": "^3.2.11",
"process": "^0.11.10"
diff --git a/packages/webpack-config/src/index.ts b/packages/webpack-config/src/index.ts
index dd187bda1b..3f0ab39271 100644
--- a/packages/webpack-config/src/index.ts
+++ b/packages/webpack-config/src/index.ts
@@ -139,7 +139,8 @@ export function getWebpackConfig(options: GetWebpackConfigOptions): Configuratio
inline: 2,
passes: 4,
},
- mangle: {
+ // If JSMinifier is swc remove mangle config because it will cause minification error.
+ mangle: minify === JSMinifier.swc ? {} : {
safari10: true,
},
format: {
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 3f9ddbb1cd..364767086d 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -947,6 +947,31 @@ importers:
specifier: ^3.12.1
version: 3.12.3
+ examples/with-intl:
+ dependencies:
+ '@ice/app':
+ specifier: workspace:*
+ version: link:../../packages/ice
+ '@ice/plugin-intl':
+ specifier: workspace:*
+ version: link:../../packages/plugin-intl
+ '@ice/runtime':
+ specifier: workspace:*
+ version: link:../../packages/runtime
+ react:
+ specifier: ^18.2.0
+ version: 18.2.0
+ react-dom:
+ specifier: ^18.2.0
+ version: 18.2.0(react@18.2.0)
+ devDependencies:
+ '@types/react':
+ specifier: ^18.0.0
+ version: 18.0.34
+ '@types/react-dom':
+ specifier: ^18.0.2
+ version: 18.0.11
+
examples/with-jest:
dependencies:
'@ice/runtime':
@@ -1653,16 +1678,16 @@ importers:
specifier: 1.2.2
version: link:../route-manifest
'@ice/rspack-config':
- specifier: 1.1.6
+ specifier: 1.1.7
version: link:../rspack-config
'@ice/runtime':
- specifier: ^1.4.5
+ specifier: ^1.4.7
version: link:../runtime
'@ice/shared-config':
- specifier: 1.2.6
+ specifier: 1.2.7
version: link:../shared-config
'@ice/webpack-config':
- specifier: 1.1.13
+ specifier: 1.1.14
version: link:../webpack-config
'@swc/helpers':
specifier: 0.5.1
@@ -2024,6 +2049,28 @@ importers:
specifier: ^18.0.0
version: 18.0.11
+ packages/plugin-intl:
+ dependencies:
+ fast-glob:
+ specifier: ^3.3.2
+ version: 3.3.2
+ react-intl:
+ specifier: ^6.0.0
+ version: 6.3.2(react@18.2.0)(typescript@4.9.5)
+ devDependencies:
+ '@ice/app':
+ specifier: ^3.3.2
+ version: link:../ice
+ '@ice/runtime':
+ specifier: ^1.2.9
+ version: link:../runtime
+ '@types/react':
+ specifier: ^18.0.0
+ version: 18.0.34
+ '@types/react-dom':
+ specifier: ^18.0.0
+ version: 18.0.11
+
packages/plugin-jsx-plus:
dependencies:
'@babel/core':
@@ -2187,7 +2234,7 @@ importers:
version: 0.9.1
devDependencies:
'@ice/app':
- specifier: ^3.4.2
+ specifier: ^3.4.8
version: link:../ice
'@types/lodash-es':
specifier: ^4.17.7
@@ -2335,7 +2382,7 @@ importers:
specifier: 0.2.6
version: link:../bundles
'@ice/shared-config':
- specifier: 1.2.6
+ specifier: 1.2.7
version: link:../shared-config
devDependencies:
'@rspack/core':
@@ -2440,7 +2487,7 @@ importers:
specifier: 0.2.6
version: link:../bundles
'@ice/shared-config':
- specifier: 1.2.6
+ specifier: 1.2.7
version: link:../shared-config
fast-glob:
specifier: ^3.2.11
@@ -10668,7 +10715,7 @@ packages:
commander: 2.20.3
consola: 2.15.3
esbuild: 0.16.17
- fast-glob: 3.3.0
+ fast-glob: 3.3.2
fs-extra: 8.1.0
json5: 2.2.3
lodash: 4.17.21
@@ -13456,6 +13503,7 @@ packages:
glob-parent: 5.1.2
merge2: 1.4.1
micromatch: 4.0.5
+ dev: false
/fast-glob@3.3.2:
resolution: {integrity: sha512-oX2ruAFQwf/Orj8m737Y5adxDQO0LAB7/S5MnxCdTNDd4p6BsyIVsv9JQsATbTSq8KHRpLwIHbVlUNatxd+1Ow==}
@@ -14079,7 +14127,7 @@ packages:
'@types/glob': 7.2.0
array-union: 2.1.0
dir-glob: 3.0.1
- fast-glob: 3.3.0
+ fast-glob: 3.3.2
glob: 7.2.3
ignore: 5.2.4
merge2: 1.4.1
@@ -14092,7 +14140,7 @@ packages:
dependencies:
array-union: 2.1.0
dir-glob: 3.0.1
- fast-glob: 3.3.0
+ fast-glob: 3.3.2
ignore: 5.2.4
merge2: 1.4.1
slash: 3.0.0
@@ -14103,7 +14151,7 @@ packages:
dependencies:
array-union: 3.0.1
dir-glob: 3.0.1
- fast-glob: 3.3.0
+ fast-glob: 3.3.2
ignore: 5.2.4
merge2: 1.4.1
slash: 4.0.0
@@ -21608,7 +21656,7 @@ packages:
css-functions-list: 3.1.0
css-tree: 2.3.1
debug: 4.3.4
- fast-glob: 3.3.0
+ fast-glob: 3.3.2
fastest-levenshtein: 1.0.16
file-entry-cache: 6.0.1
global-modules: 2.0.0