From c3a9c20aec46a4bd491a9bd5d682484da947c331 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=93=E9=99=8C=E5=90=8C=E5=AD=A6?= Date: Mon, 18 Sep 2023 17:18:20 +0800 Subject: [PATCH 1/5] chore: modify output (#6534) --- .changeset/curly-bears-mate.md | 5 +++++ packages/ice/src/bundler/config/output.ts | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 .changeset/curly-bears-mate.md diff --git a/.changeset/curly-bears-mate.md b/.changeset/curly-bears-mate.md new file mode 100644 index 0000000000..c8e3edd8e0 --- /dev/null +++ b/.changeset/curly-bears-mate.md @@ -0,0 +1,5 @@ +--- +'@ice/app': patch +--- + +chore: modify output diff --git a/packages/ice/src/bundler/config/output.ts b/packages/ice/src/bundler/config/output.ts index 1ec47ecfb5..7474461665 100644 --- a/packages/ice/src/bundler/config/output.ts +++ b/packages/ice/src/bundler/config/output.ts @@ -21,7 +21,7 @@ export async function getOutputPaths(options: { } } if (serverEntry && userConfig.htmlGenerating) { - outputPaths = await buildCustomOuputs(rootDir, outputDir, serverEntry, bundleOptions); + outputPaths = await buildCustomOutputs(rootDir, outputDir, serverEntry, bundleOptions); } return outputPaths; } @@ -32,7 +32,7 @@ export async function removeServerOutput(outputDir: string, ssr: boolean) { } } // Build custom outputs such html and js file for weex. -async function buildCustomOuputs( +async function buildCustomOutputs( rootDir: string, outputDir: string, serverEntry: string, From 82702258c46e07c2ca8644553175ee28bf53efde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=93=E9=99=8C=E5=90=8C=E5=AD=A6?= Date: Tue, 19 Sep 2023 14:14:21 +0800 Subject: [PATCH 2/5] feat: compat no document (#6536) * feat: compat no document * chore: modify if * chore: Document is not requied --- .changeset/empty-ads-sleep.md | 5 +++++ packages/ice/src/createService.ts | 2 ++ packages/ice/templates/core/entry.client.tsx.ejs | 4 ++-- packages/ice/templates/core/entry.server.ts.ejs | 16 ++++++++++------ .../ice/templates/exports/data-loader.ts.ejs | 6 +++--- packages/runtime/src/runServerApp.tsx | 10 +++++++--- 6 files changed, 29 insertions(+), 14 deletions(-) create mode 100644 .changeset/empty-ads-sleep.md diff --git a/.changeset/empty-ads-sleep.md b/.changeset/empty-ads-sleep.md new file mode 100644 index 0000000000..8c2dc8a5a2 --- /dev/null +++ b/.changeset/empty-ads-sleep.md @@ -0,0 +1,5 @@ +--- +'@ice/app': patch +--- + +feat: compat no document diff --git a/packages/ice/src/createService.ts b/packages/ice/src/createService.ts index 2b39ee2501..41177a640f 100644 --- a/packages/ice/src/createService.ts +++ b/packages/ice/src/createService.ts @@ -5,6 +5,7 @@ import { Context } from 'build-scripts'; import type { CommandArgs, CommandName } from 'build-scripts'; import type { Config } from '@ice/shared-config/types'; import type { AppConfig } from '@ice/runtime/types'; +import fse from 'fs-extra'; import webpack from '@ice/bundles/compiled/webpack/index.js'; import type { DeclarationData, @@ -274,6 +275,7 @@ async function createService({ rootDir, command, commandArgs }: CreateServiceOpt enableRoutes: true, entryCode, jsOutput: distType.includes('javascript'), + hasDocument: fse.existsSync(path.join(rootDir, 'src/document.tsx')), dataLoader: userConfig.dataLoader, routeImports, routeDefinition, diff --git a/packages/ice/templates/core/entry.client.tsx.ejs b/packages/ice/templates/core/entry.client.tsx.ejs index e1610d8f41..d48fc0d383 100644 --- a/packages/ice/templates/core/entry.client.tsx.ejs +++ b/packages/ice/templates/core/entry.client.tsx.ejs @@ -8,7 +8,7 @@ import * as app from '@/app'; import createRoutes from './routes'; <% } -%> <%- runtimeOptions.imports %> -<% if(dataLoaderImport.imports) {-%><%-dataLoaderImport.imports%><% } -%> +<% if (dataLoaderImport.imports) {-%><%-dataLoaderImport.imports%><% } -%> import type { RunClientAppOptions } from '@ice/runtime'; const getRouterBasename = () => { @@ -19,7 +19,7 @@ const getRouterBasename = () => { // Otherwise chunk of route component will pack @ice/jsx-runtime and depend on framework bundle. const App = <>; -<% if(!dataLoaderImport.imports) {-%> +<% if (!dataLoaderImport.imports) {-%> let dataLoaderFetcher = (options) => { return window.fetch(options.url, options); } diff --git a/packages/ice/templates/core/entry.server.ts.ejs b/packages/ice/templates/core/entry.server.ts.ejs index e4589082ff..bbdead1638 100644 --- a/packages/ice/templates/core/entry.server.ts.ejs +++ b/packages/ice/templates/core/entry.server.ts.ejs @@ -1,23 +1,25 @@ import './env.server'; import * as runtime from '@ice/runtime/server'; -<% if(hydrate) {-%> +<% if (hydrate) {-%> import { commons, statics } from './runtime-modules'; <% }-%> import * as app from '@/app'; +<% if (hasDocument) {-%> import * as Document from '@/document'; +<% }-%> import type { RenderMode, DistType } from '@ice/runtime'; import type { RenderToPipeableStreamOptions } from 'react-dom/server'; // @ts-ignore import assetsManifest from 'virtual:assets-manifest.json'; -<% if(hydrate) {-%> +<% if (hydrate) {-%> import createRoutes from './routes'; <% } 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) {-%> +<% if (dataLoaderImport.imports) {-%><%-dataLoaderImport.imports%><% } -%> +<% if (hydrate) {-%><%- runtimeOptions.imports %><% } -%> +<% if (!hydrate) {-%> // Do not inject runtime modules when render mode is document only. const commons = []; const statics = []; @@ -90,12 +92,14 @@ function mergeOptions(options) { assetsManifest, createRoutes, runtimeModules, + <% if (hasDocument) {-%> documentDataLoader: Document.dataLoader, Document: Document.default, + <% }-%> basename: basename || getRouterBasename(), renderMode, routesConfig, - <% if(hydrate) {-%> + <% if (hydrate) {-%> runtimeOptions: { <% if (runtimeOptions.exports) { -%> <%- runtimeOptions.exports %> diff --git a/packages/ice/templates/exports/data-loader.ts.ejs b/packages/ice/templates/exports/data-loader.ts.ejs index eff9ec5391..22ebf3eb82 100644 --- a/packages/ice/templates/exports/data-loader.ts.ejs +++ b/packages/ice/templates/exports/data-loader.ts.ejs @@ -1,7 +1,7 @@ import { dataLoader } from '@ice/runtime'; import * as app from '@/app'; import dataloaderConfig from './dataloader-config' -<% if(dataLoaderImport.imports) {-%><%-dataLoaderImport.imports%><% } -%> +<% if (dataLoaderImport.imports) {-%><%-dataLoaderImport.imports%><% } -%> <% const staticModuleNames = []; -%> <% if (runtimeModules.length) { -%> <% runtimeModules.forEach((runtimeModule, index) => { -%> @@ -14,10 +14,10 @@ import dataloaderConfig from './dataloader-config' const loaders = { ...dataloaderConfig, - <% if(hasExportAppData) {-%>__app: app.dataLoader,<% } -%> + <% if (hasExportAppData) {-%>__app: app.dataLoader,<% } -%> } -<% if(!dataLoaderImport.imports) {-%> +<% if (!dataLoaderImport.imports) {-%> let dataLoaderFetcher = (options) => { return window.fetch(options.url, options); } diff --git a/packages/runtime/src/runServerApp.tsx b/packages/runtime/src/runServerApp.tsx index 73a94b1989..6b5f631396 100644 --- a/packages/runtime/src/runServerApp.tsx +++ b/packages/runtime/src/runServerApp.tsx @@ -39,7 +39,7 @@ interface RenderOptions { createRoutes: (options: Pick) => RouteItem[]; runtimeModules: RuntimeModules; documentDataLoader?: DataLoaderConfig; - Document: DocumentComponent; + Document?: DocumentComponent; documentOnly?: boolean; renderMode?: RenderMode; // basename is used both for server and client, once set, it will be sync to client. @@ -406,7 +406,9 @@ async function renderServerEntry( - + { + Document && + } @@ -500,7 +502,9 @@ function renderDocument(options: RenderDocumentOptions): Response { const htmlStr = ReactDOMServer.renderToString( - + { + Document && + } , ); From 78f850fa675a64732ad226d51e2eef38e37398d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B0=B4=E6=BE=9C?= Date: Wed, 20 Sep 2023 15:17:28 +0800 Subject: [PATCH 3/5] feat: hash only css modules (#6289) * feat: hash only css modules * fix: type * docs: css modules hash only * chore: add changeset * refactor: support localIdentName * chore: add todo --- .changeset/short-waves-confess.md | 7 +++++++ examples/basic-project/ice.config.mts | 3 +++ packages/ice/src/config.ts | 8 ++++++++ packages/ice/src/service/ServerRunner.ts | 9 ++++++--- packages/ice/src/service/onDemandPreBundle.ts | 8 +++++++- packages/ice/src/service/preBundleDeps.ts | 7 +++++-- packages/ice/src/service/serverCompiler.ts | 3 ++- packages/ice/src/types/userConfig.ts | 1 + packages/ice/src/utils/getCSSModuleIdent.ts | 8 +++++--- .../src/getCSSModuleLocalIdent.ts | 9 ++++++++- packages/shared-config/src/types.ts | 5 +++++ packages/webpack-config/src/config/css.ts | 9 +++++---- website/docs/guide/basic/config.md | 19 +++++++++++++++++++ 13 files changed, 81 insertions(+), 15 deletions(-) create mode 100644 .changeset/short-waves-confess.md diff --git a/.changeset/short-waves-confess.md b/.changeset/short-waves-confess.md new file mode 100644 index 0000000000..5f6ae2f8f4 --- /dev/null +++ b/.changeset/short-waves-confess.md @@ -0,0 +1,7 @@ +--- +'@ice/webpack-config': patch +'@ice/shared-config': patch +'@ice/app': patch +--- + +feat: support hash only class name for css modules diff --git a/examples/basic-project/ice.config.mts b/examples/basic-project/ice.config.mts index b6c70dd853..e3040539bd 100644 --- a/examples/basic-project/ice.config.mts +++ b/examples/basic-project/ice.config.mts @@ -41,4 +41,7 @@ export default defineConfig(() => ({ customPlugin(), ], eslint: true, + cssModules: { + localIdentName: '[hash:8]', + }, })); diff --git a/packages/ice/src/config.ts b/packages/ice/src/config.ts index 4db01cee1c..ee9ec028e5 100644 --- a/packages/ice/src/config.ts +++ b/packages/ice/src/config.ts @@ -154,6 +154,14 @@ const userConfig = [ return mergeDefaultValue(config, 'postcss', postcss); }, }, + { + name: 'cssModules', + validation: 'object', + defaultValue: {}, + setConfig(config: Config, postcss: UserConfig['cssModules']) { + return mergeDefaultValue(config, 'cssModules', postcss); + }, + }, { name: 'webpack', validation: 'function', diff --git a/packages/ice/src/service/ServerRunner.ts b/packages/ice/src/service/ServerRunner.ts index 214e4ac7d3..eec7b01b32 100644 --- a/packages/ice/src/service/ServerRunner.ts +++ b/packages/ice/src/service/ServerRunner.ts @@ -112,14 +112,16 @@ class ServerRunner extends Runner { }, }, }, 'esbuild', { isServer: true }); - const { alias, ignores } = filterAlias(task.config.alias || {}); - const define = getRuntimeDefination(task.config.define || {}); + const taskConfig = task.config; + const { alias, ignores } = filterAlias(taskConfig.alias || {}); + const define = getRuntimeDefination(taskConfig.define || {}); const runtimeMeta = new RuntimeMeta({ rootDir, alias, ignores, external: server.externals || [], define, + taskConfig, speedup, }); @@ -140,8 +142,9 @@ class ServerRunner extends Runner { // ServerRunner only works in development mode. mode: 'development', fileName, - localIdentName: name, + localName: name, rule: speedup ? 'native' : 'loader', + localIdentName: taskConfig.cssModules?.localIdentName, }); }, }), diff --git a/packages/ice/src/service/onDemandPreBundle.ts b/packages/ice/src/service/onDemandPreBundle.ts index cefc4b3738..121562ca51 100644 --- a/packages/ice/src/service/onDemandPreBundle.ts +++ b/packages/ice/src/service/onDemandPreBundle.ts @@ -3,6 +3,7 @@ import { createRequire } from 'module'; import fse from 'fs-extra'; import findUp from 'find-up'; import type { Plugin } from 'esbuild'; +import type { Config } from '@ice/shared-config/types'; import { logger } from '../utils/logger.js'; import { CACHE_DIR } from '../constant.js'; import { bundleDeps, resolvePackageESEntry, getDepsCacheDir } from './preBundleDeps.js'; @@ -24,6 +25,7 @@ interface PreBundleOptions { plugins?: Plugin[]; external?: string[]; define?: Record; + taskConfig?: Config; speedup?: boolean; } @@ -36,6 +38,7 @@ export class RuntimeMeta { private cachePath: string; private external: string[]; private define: Record; + private taskConfig: Config; private speedup: boolean; constructor(options: Omit) { @@ -47,6 +50,7 @@ export class RuntimeMeta { this.define = options.define; this.speedup = options.speedup; this.cachePath = path.join(getDepsCacheDir(path.join(this.rootDir, CACHE_DIR)), 'metadata.json'); + this.taskConfig = options.taskConfig; } async getDepsCache() { @@ -100,6 +104,7 @@ export class RuntimeMeta { define: this.define, pkgName: pkgName, resolveId, + taskConfig: this.taskConfig, speedup: this.speedup, }); await this.setDepsCache(pkgName, resolveId, bundlePath); @@ -111,7 +116,7 @@ export class RuntimeMeta { } export default async function preBundleDeps(options: PreBundleOptions): Promise { - const { rootDir, pkgName, alias, ignores, plugins, resolveId, external, define, speedup } = options; + const { rootDir, pkgName, alias, ignores, plugins, resolveId, external, define, speedup, taskConfig } = options; const depsCacheDir = getDepsCacheDir(path.join(rootDir, CACHE_DIR)); try { await bundleDeps({ @@ -122,6 +127,7 @@ export default async function preBundleDeps(options: PreBundleOptions): Promise< plugins: plugins || [], external, define, + taskConfig, speedup, rootDir, }); diff --git a/packages/ice/src/service/preBundleDeps.ts b/packages/ice/src/service/preBundleDeps.ts index a994ab1b36..fb4c4783c8 100644 --- a/packages/ice/src/service/preBundleDeps.ts +++ b/packages/ice/src/service/preBundleDeps.ts @@ -104,6 +104,7 @@ export default async function preBundleDeps( alias, external, define, + taskConfig, speedup, }); @@ -129,9 +130,10 @@ export async function bundleDeps(options: plugins: Plugin[]; external: string[]; define: BuildOptions['define']; + taskConfig: Config; speedup?: boolean; }) { - const { entryPoints, outdir, alias, ignores, plugins, external, define, speedup, rootDir } = options; + const { entryPoints, outdir, alias, ignores, plugins, external, define, speedup, rootDir, taskConfig } = options; return await esbuild.build({ absWorkingDir: process.cwd(), entryPoints, @@ -162,8 +164,9 @@ export async function bundleDeps(options: // Prebundle only works in development mode. mode: 'development', fileName, - localIdentName: name, + localName: name, rule: speedup ? 'native' : 'loader', + localIdentName: taskConfig.cssModules?.localIdentName, }); }, }), diff --git a/packages/ice/src/service/serverCompiler.ts b/packages/ice/src/service/serverCompiler.ts index 2118de2302..fd40727ea7 100644 --- a/packages/ice/src/service/serverCompiler.ts +++ b/packages/ice/src/service/serverCompiler.ts @@ -205,8 +205,9 @@ export function createServerCompiler(options: Options) { rootDir, mode: dev ? 'development' : 'production', fileName, - localIdentName: name, + localName: name, rule: speedup ? 'native' : 'loader', + localIdentName: task.config.cssModules?.localIdentName, }); }, }), diff --git a/packages/ice/src/types/userConfig.ts b/packages/ice/src/types/userConfig.ts index bbf2435c21..a1f96f8a49 100644 --- a/packages/ice/src/types/userConfig.ts +++ b/packages/ice/src/types/userConfig.ts @@ -117,6 +117,7 @@ export interface UserConfig { postcss?: ProcessOptions & { plugins?: (string | [string, Record?])[]; }; + cssModules?: Config['cssModules']; /** * Custom file-system based route rules. * @see https://v3.ice.work/docs/guide/basic/config#routes diff --git a/packages/ice/src/utils/getCSSModuleIdent.ts b/packages/ice/src/utils/getCSSModuleIdent.ts index ae4b1927d0..9d8c46236c 100644 --- a/packages/ice/src/utils/getCSSModuleIdent.ts +++ b/packages/ice/src/utils/getCSSModuleIdent.ts @@ -9,17 +9,19 @@ interface Options { rule?: string; mode?: 'development' | 'production'; fileName: string; + localName: string; localIdentName: string; } +// TODO: move this logic to getCSSModuleLocalIdent. const getCSSModuleIdent = (options: Options) => { - const { rootDir, fileName, localIdentName, rule, mode } = options; + const { rootDir, fileName, localName, localIdentName, rule, mode } = options; if (rule === 'native') { const template = mode === 'development' ? CSS_MODULES_LOCAL_IDENT_NAME_DEV : CSS_MODULES_LOCAL_IDENT_NAME; const relativePath = path.isAbsolute(fileName) ? path.relative(rootDir, fileName) : fileName; - return getIdentByRust(relativePath, localIdentName, template); + return getIdentByRust(relativePath, localName, localIdentName || template); } else { - return escapeLocalIdent(getCSSModuleLocalIdent(fileName, localIdentName)); + return escapeLocalIdent(getCSSModuleLocalIdent(fileName, localName, localIdentName)); } }; diff --git a/packages/shared-config/src/getCSSModuleLocalIdent.ts b/packages/shared-config/src/getCSSModuleLocalIdent.ts index 90e2d36241..e55bc2a656 100644 --- a/packages/shared-config/src/getCSSModuleLocalIdent.ts +++ b/packages/shared-config/src/getCSSModuleLocalIdent.ts @@ -1,6 +1,12 @@ import { createHash } from 'crypto'; +import { getCssModulesLocalIdent as getIdentByRust } from '@ice/bundles'; + +export default function getCSSModuleLocalIdent(filename: string, localName: string, localIdentName: string): string { + // https://webpack.js.org/loaders/css-loader/#localidentname + if (localIdentName) { + return getIdentByRust(filename, localName, localIdentName); + } -export default function getCSSModuleLocalIdent(filename: string, localName: string) { const hash = createHash('md5'); hash.update(Buffer.from(filename + localName, 'utf8')); const localIdentHash = hash.digest('base64') @@ -11,5 +17,6 @@ export default function getCSSModuleLocalIdent(filename: string, localName: stri // Remove everything that is not an alphanumeric or underscore .replace(/[^A-Za-z0-9_]+/g, '') .slice(0, 8); + return `${localName}--${localIdentHash}`; } diff --git a/packages/shared-config/src/types.ts b/packages/shared-config/src/types.ts index 6266da42ce..42192a9a7b 100644 --- a/packages/shared-config/src/types.ts +++ b/packages/shared-config/src/types.ts @@ -180,6 +180,11 @@ export interface Config { cssChunkFilename?: string; postcss?: ProcessOptions & { plugins?: (string | [string, Record?])[] }; + + cssModules?: { + localIdentName?: string; + }; + enableCopyPlugin?: boolean; enableRpx2Vw?: boolean; diff --git a/packages/webpack-config/src/config/css.ts b/packages/webpack-config/src/config/css.ts index 7e45e6a759..9e5f837a09 100644 --- a/packages/webpack-config/src/config/css.ts +++ b/packages/webpack-config/src/config/css.ts @@ -13,12 +13,13 @@ interface Options { postcssOptions: Config['postcss']; rootDir: string; enableRpx2Vw: boolean; + cssModules: Config['cssModules']; } const require = createRequire(import.meta.url); function configCSSRule(config: CSSRuleConfig, options: Options) { - const { publicPath, rootDir, enableRpx2Vw, postcssOptions: userPostcssOptions } = options; + const { publicPath, rootDir, enableRpx2Vw, postcssOptions: userPostcssOptions, cssModules } = options; const [style, loader, loaderOptions] = config; const cssLoaderOpts = { sourceMap: true, @@ -28,7 +29,7 @@ function configCSSRule(config: CSSRuleConfig, options: Options) { modules: { auto: (resourcePath: string) => resourcePath.endsWith(`.module.${style}`), getLocalIdent: (context: LoaderContext, localIdentName: string, localName: string) => { - return getCSSModuleLocalIdent(context.resourcePath, localName); + return getCSSModuleLocalIdent(context.resourcePath, localName, cssModules?.localIdentName); }, }, }; @@ -64,7 +65,7 @@ function configCSSRule(config: CSSRuleConfig, options: Options) { } const css: ModifyWebpackConfig = (config, ctx) => { - const { publicPath, hashKey, cssFilename, cssChunkFilename, postcss, rootDir, enableRpx2Vw } = ctx; + const { publicPath, hashKey, cssFilename, cssChunkFilename, postcss, rootDir, enableRpx2Vw, cssModules } = ctx; const cssOutputFolder = 'css'; config.module.rules.push(...([ ['css'], @@ -76,7 +77,7 @@ const css: ModifyWebpackConfig = (config, ctx) => implementation: sass, }], ] as CSSRuleConfig[]).map((config) => configCSSRule(config, { - publicPath, postcssOptions: postcss, rootDir, enableRpx2Vw }, + publicPath, postcssOptions: postcss, rootDir, enableRpx2Vw, cssModules }, ))); config.plugins.push( new MiniCssExtractPlugin({ diff --git a/website/docs/guide/basic/config.md b/website/docs/guide/basic/config.md index 81f599fe7b..271cccdf94 100644 --- a/website/docs/guide/basic/config.md +++ b/website/docs/guide/basic/config.md @@ -712,4 +712,23 @@ export default defineConfig(() => ({ })); ``` +### cssModules + +- 类型:`{ localIdentName: string }` +- 默认值:`{}` + +构建 cssModules 时,定制 class 名称的生成规则,配置参考 https://webpack.js.org/loaders/css-loader/#localidentname + +例如,配置 '[hash:8]' 可以只保留 hash 值,以精简 HTML 大小及 CSS 文件大小。默认情况 `className="custom-head-tab-wrap"` 会被构建为 `class="custom-head-tab-wrap--rAEgGaqM"`,自定义构建规则后后样式名会被精简为 `class="rAEgGaqM"`。 + +```js +import { defineConfig } from '@ice/app'; + +export default defineConfig(() => ({ + cssModules: { + localIdentName: '[hash:8]' + }, +})); +``` + > 如有定制需求欢迎👏 PR 或反馈: From f2c7df96afa55e18187cada4905a7a36139ee0f3 Mon Sep 17 00:00:00 2001 From: ClarkXia Date: Thu, 21 Sep 2023 10:56:01 +0800 Subject: [PATCH 4/5] feat: new plugin deal with stream error (#6530) * feat: new plugin deal with stream error * fix: add options for local test --- .changeset/twenty-pens-remain.md | 5 ++++ packages/plugin-stream-error/README.md | 18 +++++++++++ packages/plugin-stream-error/package.json | 35 ++++++++++++++++++++++ packages/plugin-stream-error/src/index.ts | 30 +++++++++++++++++++ packages/plugin-stream-error/tsconfig.json | 10 +++++++ pnpm-lock.yaml | 6 ++++ 6 files changed, 104 insertions(+) create mode 100644 .changeset/twenty-pens-remain.md create mode 100644 packages/plugin-stream-error/README.md create mode 100644 packages/plugin-stream-error/package.json create mode 100644 packages/plugin-stream-error/src/index.ts create mode 100644 packages/plugin-stream-error/tsconfig.json diff --git a/.changeset/twenty-pens-remain.md b/.changeset/twenty-pens-remain.md new file mode 100644 index 0000000000..8b8e90c24c --- /dev/null +++ b/.changeset/twenty-pens-remain.md @@ -0,0 +1,5 @@ +--- +'@ice/plugin-stream-error': major +--- + +feat: plugin deal with stream error diff --git a/packages/plugin-stream-error/README.md b/packages/plugin-stream-error/README.md new file mode 100644 index 0000000000..8d9e711a98 --- /dev/null +++ b/packages/plugin-stream-error/README.md @@ -0,0 +1,18 @@ +# @ice/plugin-stream-error + +A plugin for re-render app when stream error. + +## Usage + +```ts +import { defineConfig } from '@ice/app'; +import streamError from '@ice/plugin-stream-error'; + +export default defineConfig(() => ({ + plugins: [ + streamError(), + ], +})); +``` + +> Causion: This plugin only works when stream content ends with javascripts which triggered an custom event of `stream_end` diff --git a/packages/plugin-stream-error/package.json b/packages/plugin-stream-error/package.json new file mode 100644 index 0000000000..6b1a424d5a --- /dev/null +++ b/packages/plugin-stream-error/package.json @@ -0,0 +1,35 @@ +{ + "name": "@ice/plugin-stream-error", + "version": "0.0.0", + "description": "", + "license": "MIT", + "type": "module", + "exports": { + ".": { + "types": "./esm/index.d.ts", + "import": "./esm/index.js", + "default": "./esm/index.js" + } + }, + "main": "./esm/index.js", + "types": "./esm/index.d.ts", + "files": [ + "esm", + "!esm/**/*.map", + "*.d.ts" + ], + "devDependencies": { + "@ice/app": "workspace:^" + }, + "repository": { + "type": "http", + "url": "https://github.com/alibaba/ice/tree/master/packages/plugin-store" + }, + "scripts": { + "watch": "tsc -w --sourceMap", + "build": "tsc" + }, + "publishConfig": { + "access": "public" + } +} diff --git a/packages/plugin-stream-error/src/index.ts b/packages/plugin-stream-error/src/index.ts new file mode 100644 index 0000000000..9a49983ef3 --- /dev/null +++ b/packages/plugin-stream-error/src/index.ts @@ -0,0 +1,30 @@ +import type { Plugin } from '@ice/app/types'; + +interface PluginOptions { + activeInDev?: boolean; +} + +const PLUGIN_NAME = '@ice/plugin-stream-error'; +const plugin: Plugin = (options = {}) => ({ + name: PLUGIN_NAME, + setup: ({ generator, context }) => { + const { activeInDev } = options; + const { userConfig } = context; + if (userConfig.ssr) { + generator.addEntryCode((originalCode) => { + return `${originalCode} +if (import.meta.renderer === 'client') { + window.addEventListener('load', (event) => { + // _$ServerTimePoints will returned at the end of last stream, + // if the value is undefined, try to re-render app with CSR. + if (${activeInDev ? '' : 'process.env.NODE_ENV === \'production\' && '}!window._$ServerTimePoints && window.__ICE_APP_CONTEXT__.renderMode === 'SSR') { + render({ hydrate: false }); + } + }); +}`; + }); + } + }, +}); + +export default plugin; diff --git a/packages/plugin-stream-error/tsconfig.json b/packages/plugin-stream-error/tsconfig.json new file mode 100644 index 0000000000..769280c92d --- /dev/null +++ b/packages/plugin-stream-error/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "baseUrl": "./", + "rootDir": "src", + "outDir": "esm", + "jsx": "react" + }, + "include": ["src"] +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 956eca5b40..2fe4f51e2b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1541,6 +1541,12 @@ importers: react-dom: 18.2.0_react@18.2.0 regenerator-runtime: 0.13.11 + packages/plugin-stream-error: + specifiers: + '@ice/app': workspace:^ + devDependencies: + '@ice/app': link:../ice + packages/rax-compat: specifiers: '@ice/appear': ^0.2.1 From 40f1071940e21c342ac04006a31b5b627e241779 Mon Sep 17 00:00:00 2001 From: ClarkXia Date: Thu, 21 Sep 2023 15:17:00 +0800 Subject: [PATCH 5/5] chore: update versions (#6537) --- .changeset/curly-bears-mate.md | 5 ----- .changeset/empty-ads-sleep.md | 5 ----- .changeset/short-waves-confess.md | 7 ------- .changeset/twenty-pens-remain.md | 5 ----- packages/ice/CHANGELOG.md | 12 ++++++++++++ packages/ice/package.json | 8 ++++---- packages/plugin-i18n/package.json | 2 +- packages/plugin-stream-error/CHANGELOG.md | 7 +++++++ packages/plugin-stream-error/package.json | 2 +- packages/rspack-config/CHANGELOG.md | 7 +++++++ packages/rspack-config/package.json | 4 ++-- packages/shared-config/CHANGELOG.md | 6 ++++++ packages/shared-config/package.json | 2 +- packages/webpack-config/CHANGELOG.md | 8 ++++++++ packages/webpack-config/package.json | 4 ++-- pnpm-lock.yaml | 10 +++++----- 16 files changed, 56 insertions(+), 38 deletions(-) delete mode 100644 .changeset/curly-bears-mate.md delete mode 100644 .changeset/empty-ads-sleep.md delete mode 100644 .changeset/short-waves-confess.md delete mode 100644 .changeset/twenty-pens-remain.md create mode 100644 packages/plugin-stream-error/CHANGELOG.md diff --git a/.changeset/curly-bears-mate.md b/.changeset/curly-bears-mate.md deleted file mode 100644 index c8e3edd8e0..0000000000 --- a/.changeset/curly-bears-mate.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@ice/app': patch ---- - -chore: modify output diff --git a/.changeset/empty-ads-sleep.md b/.changeset/empty-ads-sleep.md deleted file mode 100644 index 8c2dc8a5a2..0000000000 --- a/.changeset/empty-ads-sleep.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@ice/app': patch ---- - -feat: compat no document diff --git a/.changeset/short-waves-confess.md b/.changeset/short-waves-confess.md deleted file mode 100644 index 5f6ae2f8f4..0000000000 --- a/.changeset/short-waves-confess.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -'@ice/webpack-config': patch -'@ice/shared-config': patch -'@ice/app': patch ---- - -feat: support hash only class name for css modules diff --git a/.changeset/twenty-pens-remain.md b/.changeset/twenty-pens-remain.md deleted file mode 100644 index 8b8e90c24c..0000000000 --- a/.changeset/twenty-pens-remain.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@ice/plugin-stream-error': major ---- - -feat: plugin deal with stream error diff --git a/packages/ice/CHANGELOG.md b/packages/ice/CHANGELOG.md index 8fae3b8f9a..c3cff9eb19 100644 --- a/packages/ice/CHANGELOG.md +++ b/packages/ice/CHANGELOG.md @@ -1,5 +1,17 @@ # Changelog +## 3.3.3 + +### Patch Changes + +- c3a9c20a: chore: modify output +- 82702258: feat: compat no document +- 78f850fa: feat: support hash only class name for css modules +- Updated dependencies [78f850fa] + - @ice/webpack-config@1.1.3 + - @ice/shared-config@1.0.4 + - @ice/rspack-config@1.0.4 + ## 3.3.2 ### Patch Changes diff --git a/packages/ice/package.json b/packages/ice/package.json index dd455e2910..053c0879d8 100644 --- a/packages/ice/package.json +++ b/packages/ice/package.json @@ -1,6 +1,6 @@ { "name": "@ice/app", - "version": "3.3.2", + "version": "3.3.3", "description": "provide scripts and configuration used by web framework ice", "type": "module", "main": "./esm/index.js", @@ -40,9 +40,9 @@ "@ice/bundles": "0.1.16", "@ice/route-manifest": "1.2.2", "@ice/runtime": "^1.2.9", - "@ice/shared-config": "1.0.3", - "@ice/webpack-config": "1.1.2", - "@ice/rspack-config": "1.0.3", + "@ice/shared-config": "1.0.4", + "@ice/webpack-config": "1.1.3", + "@ice/rspack-config": "1.0.4", "@swc/helpers": "0.5.1", "@types/express": "^4.17.14", "address": "^1.1.2", diff --git a/packages/plugin-i18n/package.json b/packages/plugin-i18n/package.json index 1a6e7263ab..6b042c7535 100644 --- a/packages/plugin-i18n/package.json +++ b/packages/plugin-i18n/package.json @@ -56,7 +56,7 @@ "webpack-dev-server": "^4.13.2" }, "peerDependencies": { - "@ice/app": "^3.3.2", + "@ice/app": "^3.3.3", "@ice/runtime": "^1.2.9" }, "publishConfig": { diff --git a/packages/plugin-stream-error/CHANGELOG.md b/packages/plugin-stream-error/CHANGELOG.md new file mode 100644 index 0000000000..857067ff71 --- /dev/null +++ b/packages/plugin-stream-error/CHANGELOG.md @@ -0,0 +1,7 @@ +# @ice/plugin-stream-error + +## 1.0.0 + +### Major Changes + +- f2c7df96: feat: plugin deal with stream error diff --git a/packages/plugin-stream-error/package.json b/packages/plugin-stream-error/package.json index 6b1a424d5a..f59ce11ee5 100644 --- a/packages/plugin-stream-error/package.json +++ b/packages/plugin-stream-error/package.json @@ -1,6 +1,6 @@ { "name": "@ice/plugin-stream-error", - "version": "0.0.0", + "version": "1.0.0", "description": "", "license": "MIT", "type": "module", diff --git a/packages/rspack-config/CHANGELOG.md b/packages/rspack-config/CHANGELOG.md index 0455fa154d..6ed8a8b163 100644 --- a/packages/rspack-config/CHANGELOG.md +++ b/packages/rspack-config/CHANGELOG.md @@ -1,5 +1,12 @@ # @ice/rspack-config +## 1.0.4 + +### Patch Changes + +- Updated dependencies [78f850fa] + - @ice/shared-config@1.0.4 + ## 1.0.3 ### Patch Changes diff --git a/packages/rspack-config/package.json b/packages/rspack-config/package.json index 4440b9f072..af28f91eca 100644 --- a/packages/rspack-config/package.json +++ b/packages/rspack-config/package.json @@ -1,6 +1,6 @@ { "name": "@ice/rspack-config", - "version": "1.0.3", + "version": "1.0.4", "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.0.3", + "@ice/shared-config": "1.0.4", "@ice/bundles": "0.1.16" }, "devDependencies": { diff --git a/packages/shared-config/CHANGELOG.md b/packages/shared-config/CHANGELOG.md index 854b34509a..d639572687 100644 --- a/packages/shared-config/CHANGELOG.md +++ b/packages/shared-config/CHANGELOG.md @@ -1,5 +1,11 @@ # @ice/shared-config +## 1.0.4 + +### Patch Changes + +- 78f850fa: feat: support hash only class name for css modules + ## 1.0.3 ### Patch Changes diff --git a/packages/shared-config/package.json b/packages/shared-config/package.json index 672841409f..b74aeac889 100644 --- a/packages/shared-config/package.json +++ b/packages/shared-config/package.json @@ -1,6 +1,6 @@ { "name": "@ice/shared-config", - "version": "1.0.3", + "version": "1.0.4", "repository": "alibaba/ice", "bugs": "https://github.com/alibaba/ice/issues", "homepage": "https://v3.ice.work", diff --git a/packages/webpack-config/CHANGELOG.md b/packages/webpack-config/CHANGELOG.md index 04920d7b2e..af8349fec5 100644 --- a/packages/webpack-config/CHANGELOG.md +++ b/packages/webpack-config/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## 1.1.3 + +### Patch Changes + +- 78f850fa: feat: support hash only class name for css modules +- Updated dependencies [78f850fa] + - @ice/shared-config@1.0.4 + ## 1.1.2 ### Patch Changes diff --git a/packages/webpack-config/package.json b/packages/webpack-config/package.json index d809f236bc..e45081421b 100644 --- a/packages/webpack-config/package.json +++ b/packages/webpack-config/package.json @@ -1,6 +1,6 @@ { "name": "@ice/webpack-config", - "version": "1.1.2", + "version": "1.1.3", "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.0.3", + "@ice/shared-config": "1.0.4", "@ice/bundles": "0.1.16", "fast-glob": "^3.2.11", "process": "^0.11.10" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2fe4f51e2b..0f1bc0dcda 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1097,10 +1097,10 @@ importers: specifiers: '@ice/bundles': 0.1.16 '@ice/route-manifest': 1.2.2 - '@ice/rspack-config': 1.0.3 + '@ice/rspack-config': 1.0.4 '@ice/runtime': ^1.2.9 - '@ice/shared-config': 1.0.3 - '@ice/webpack-config': 1.1.2 + '@ice/shared-config': 1.0.4 + '@ice/webpack-config': 1.1.3 '@rspack/core': 0.3.0 '@rspack/dev-server': 0.3.0 '@swc/helpers': 0.5.1 @@ -1583,7 +1583,7 @@ importers: packages/rspack-config: specifiers: '@ice/bundles': 0.1.16 - '@ice/shared-config': 1.0.3 + '@ice/shared-config': 1.0.4 '@rspack/core': ^0.3.0 dependencies: '@ice/bundles': link:../bundles @@ -1672,7 +1672,7 @@ importers: packages/webpack-config: specifiers: '@ice/bundles': 0.1.16 - '@ice/shared-config': 1.0.3 + '@ice/shared-config': 1.0.4 fast-glob: ^3.2.11 process: ^0.11.10 webpack: ^5.88.0