diff --git a/.changeset/moody-snakes-study.md b/.changeset/moody-snakes-study.md new file mode 100644 index 0000000000..c5758897ed --- /dev/null +++ b/.changeset/moody-snakes-study.md @@ -0,0 +1,10 @@ +--- +"@lynx-js/rspeedy": patch +"@lynx-js/template-webpack-plugin": patch +--- + +feat: opt-in the web platform's new binary output format + +Introduce a new flag to enable the new binary output format. + +Currently it's an internal-use-only flag that will be removed in the future; set the corresponding environment variable to 'true' to enable it. diff --git a/packages/webpack/template-webpack-plugin/package.json b/packages/webpack/template-webpack-plugin/package.json index 84e413db4c..890e31db88 100644 --- a/packages/webpack/template-webpack-plugin/package.json +++ b/packages/webpack/template-webpack-plugin/package.json @@ -38,6 +38,7 @@ "dependencies": { "@lynx-js/css-serializer": "workspace:*", "@lynx-js/tasm": "0.0.20", + "@lynx-js/web-core-wasm": "workspace:*", "@lynx-js/webpack-runtime-globals": "workspace:^", "@rspack/lite-tapable": "1.1.0", "css-tree": "^3.1.0", @@ -46,7 +47,6 @@ "devDependencies": { "@lynx-js/test-tools": "workspace:*", "@lynx-js/vitest-setup": "workspace:*", - "@lynx-js/web-core-wasm": "workspace:*", "@microsoft/api-extractor": "catalog:", "@types/css-tree": "^2.3.11", "@types/object.groupby": "^1.0.4", diff --git a/packages/webpack/template-webpack-plugin/src/WebEncodePlugin.ts b/packages/webpack/template-webpack-plugin/src/WebEncodePlugin.ts index 9eacd47caa..eca646e4b3 100644 --- a/packages/webpack/template-webpack-plugin/src/WebEncodePlugin.ts +++ b/packages/webpack/template-webpack-plugin/src/WebEncodePlugin.ts @@ -102,22 +102,15 @@ export class WebEncodePlugin { customSections: encodeOptions.customSections ?? {}, elementTemplates: encodeOptions['elementTemplates'] ?? {}, }; - const isExperimentalWebBinary = !!process + const isExperimentalWebBinary = process .env['EXPERIMENTAL_USE_WEB_BINARY_TEMPLATE']; - if (isExperimentalWebBinary) { - const { encode } = await import('@lynx-js/web-core-wasm/encode') - .catch( - () => { - throw new Error( - `FLAG EXPERIMENTAL_USE_WEB_BINARY_TEMPLATE IS INTERNAL USED ONLY`, - ); - }, - ); + if (isExperimentalWebBinary === 'true') { + const { encode } = await import('@lynx-js/web-core-wasm/encode'); return { buffer: Buffer.from(encode(tasmJSONInfo as TasmJSONInfo)), debugInfo: '', }; - } else { + } else if (isExperimentalWebBinary == null /*undefined or null */) { return { buffer: Buffer.from( JSON.stringify({ @@ -133,6 +126,11 @@ export class WebEncodePlugin { ), debugInfo: '', }; + } else { + // only allow 'true' or undefined/null + throw new Error( + `Unknown value of EXPERIMENTAL_USE_WEB_BINARY_TEMPLATE: ${isExperimentalWebBinary}. Expecting "true" or undefined.`, + ); } }); }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index cacbb74b81..2e20085a6a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1638,6 +1638,9 @@ importers: '@lynx-js/tasm': specifier: 0.0.20 version: 0.0.20 + '@lynx-js/web-core-wasm': + specifier: workspace:* + version: link:../../web-platform/web-core-wasm '@lynx-js/webpack-runtime-globals': specifier: workspace:^ version: link:../webpack-runtime-globals @@ -1657,9 +1660,6 @@ importers: '@lynx-js/vitest-setup': specifier: workspace:* version: link:../../tools/vitest-setup - '@lynx-js/web-core-wasm': - specifier: workspace:* - version: link:../../web-platform/web-core-wasm '@microsoft/api-extractor': specifier: 'catalog:' version: 7.57.6(@types/node@24.10.13)