-
Notifications
You must be signed in to change notification settings - Fork 124
feat(webpack-plugin): init externals-loading-webpack-plugin #1924
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
luhc228
merged 8 commits into
lynx-family:main
from
luhc228:feat/init-externals-loading-webpack-plugin
Dec 15, 2025
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
35f58dd
feat(webpack-plugin): init externals-loading-webpack-plugin
luhc228 df6a91f
Merge branch 'main' into feat/init-externals-loading-webpack-plugin
luhc228 2b1ab4e
fix: lock is outdated
luhc228 5ffc6ea
feat: add react externals example (#1)
upupming 3e1aefe
fix: make ci pass
upupming 38c2a94
feat: use @lynx-js/react-alias-rsbuild-plugin for alias
upupming 4590302
Merge branch 'main' into feat/init-externals-loading-webpack-plugin
luhc228 390d07a
chore: update changelog
luhc228 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| --- | ||
| "@lynx-js/externals-loading-webpack-plugin": patch | ||
| --- | ||
|
|
||
| Introduce `@lynx-js/externals-loading-webpack-plugin`. | ||
|
|
||
| ```js | ||
| // webpack.config.js | ||
| import { ExternalsLoadingPlugin } from '@lynx-js/externals-loading-webpack-plugin'; | ||
|
|
||
| export default { | ||
| plugins: [ | ||
| new ExternalsLoadingPlugin({ | ||
| mainThreadChunks: ['index__main-thread'], | ||
| backgroundChunks: ['index'], | ||
| mainThreadLayer: 'main-thread', | ||
| backgroundLayer: 'background', | ||
| externals: { | ||
| lodash: { | ||
| url: 'http://lodash.lynx.bundle', | ||
| background: { sectionPath: 'background' }, | ||
| mainThread: { sectionPath: 'main-thread' }, | ||
| }, | ||
| }, | ||
| }), | ||
| ], | ||
| }; | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # @lynx-js/example-react-externals | ||
|
|
||
| In this example, we show: | ||
|
|
||
| - Use `@lynx-js/lynx-bundle-rslib-config` to bundle ReactLynx runtime to a separate Lynx bundle. | ||
| - Use `@lynx-js/lynx-bundle-rslib-config` to bundle a simple ReactLynx component library to a separate Lynx bundle. | ||
| - Use `@lynx-js/externals-loading-webpack-plugin` to load ReactLynx runtime (sync) and component bundle (async). | ||
|
|
||
| ## Usage | ||
|
|
||
| ```bash | ||
| pnpm build:reactlynx | ||
| pnpm build:comp-lib | ||
| pnpx http-server -p 8080 dist | ||
| EXTERNAL_BUNDLE_PREFIX=http://${YOUR_IP_HERE}:8080 pnpm dev | ||
| ``` | ||
|
upupming marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { App } from '../src/App.js'; | ||
|
luhc228 marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| export * as React from '@lynx-js/react'; | ||
| export * as ReactInternal from '@lynx-js/react/internal'; | ||
| export * as ReactLazyImport from '@lynx-js/react/experimental/lazy/import'; | ||
| export * as ReactLegacyRuntime from '@lynx-js/react/legacy-react-runtime'; | ||
| export * as ReactComponents from '@lynx-js/react/runtime-components'; | ||
| export * as ReactWorkletRuntime from '@lynx-js/react/worklet-runtime/bindings'; | ||
| export * as ReactDebug from '@lynx-js/react/debug'; | ||
| // @ts-expect-error preact is aliased by rspeedy | ||
| // eslint-disable-next-line import/no-unresolved | ||
| export * as Preact from 'preact'; | ||
|
luhc228 marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| import { ExternalsLoadingPlugin } from '@lynx-js/externals-loading-webpack-plugin'; | ||
| import { pluginQRCode } from '@lynx-js/qrcode-rsbuild-plugin'; | ||
| import { LAYERS, pluginReactLynx } from '@lynx-js/react-rsbuild-plugin'; | ||
| import { defineConfig } from '@lynx-js/rspeedy'; | ||
|
|
||
| const enableBundleAnalysis = !!process.env['RSPEEDY_BUNDLE_ANALYSIS']; | ||
| const EXTERNAL_BUNDLE_PREFIX = process.env['EXTERNAL_BUNDLE_PREFIX'] || ''; | ||
|
|
||
| export default defineConfig({ | ||
| tools: { | ||
| rspack: { | ||
| plugins: [ | ||
| new ExternalsLoadingPlugin({ | ||
| mainThreadChunks: ['main__main-thread'], | ||
| backgroundChunks: ['main'], | ||
| mainThreadLayer: LAYERS.MAIN_THREAD, | ||
| backgroundLayer: LAYERS.BACKGROUND, | ||
| externals: { | ||
| '@lynx-js/react': { | ||
| libraryName: ['ReactLynx', 'React'], | ||
| url: `${EXTERNAL_BUNDLE_PREFIX}/react.lynx.bundle`, | ||
| background: { sectionPath: 'ReactLynx' }, | ||
| mainThread: { sectionPath: 'ReactLynx__main-thread' }, | ||
| async: false, | ||
| }, | ||
| '@lynx-js/react/internal': { | ||
| libraryName: ['ReactLynx', 'ReactInternal'], | ||
| url: `${EXTERNAL_BUNDLE_PREFIX}/react.lynx.bundle`, | ||
| background: { sectionPath: 'ReactLynx' }, | ||
| mainThread: { sectionPath: 'ReactLynx__main-thread' }, | ||
| async: false, | ||
| }, | ||
| '@lynx-js/react/experimental/lazy/import': { | ||
| libraryName: ['ReactLynx', 'ReactLazyImport'], | ||
| url: `${EXTERNAL_BUNDLE_PREFIX}/react.lynx.bundle`, | ||
| background: { sectionPath: 'ReactLynx' }, | ||
| mainThread: { sectionPath: 'ReactLynx__main-thread' }, | ||
| async: false, | ||
| }, | ||
| '@lynx-js/react/legacy-react-runtime': { | ||
| libraryName: ['ReactLynx', 'ReactLegacyRuntime'], | ||
| url: `${EXTERNAL_BUNDLE_PREFIX}/react.lynx.bundle`, | ||
| background: { sectionPath: 'ReactLynx' }, | ||
| mainThread: { sectionPath: 'ReactLynx__main-thread' }, | ||
| async: false, | ||
| }, | ||
| '@lynx-js/react/runtime-components': { | ||
| libraryName: ['ReactLynx', 'ReactComponents'], | ||
| url: `${EXTERNAL_BUNDLE_PREFIX}/react.lynx.bundle`, | ||
| background: { sectionPath: 'ReactLynx' }, | ||
| mainThread: { sectionPath: 'ReactLynx__main-thread' }, | ||
| async: false, | ||
| }, | ||
| '@lynx-js/react/worklet-runtime/bindings': { | ||
| libraryName: ['ReactLynx', 'ReactWorkletRuntime'], | ||
| url: `${EXTERNAL_BUNDLE_PREFIX}/react.lynx.bundle`, | ||
| background: { sectionPath: 'ReactLynx' }, | ||
| mainThread: { sectionPath: 'ReactLynx__main-thread' }, | ||
| async: false, | ||
| }, | ||
| '@lynx-js/react/debug': { | ||
| libraryName: ['ReactLynx', 'ReactDebug'], | ||
| url: `${EXTERNAL_BUNDLE_PREFIX}/react.lynx.bundle`, | ||
| background: { sectionPath: 'ReactLynx' }, | ||
| mainThread: { sectionPath: 'ReactLynx__main-thread' }, | ||
| async: false, | ||
| }, | ||
| preact: { | ||
| libraryName: ['ReactLynx', 'Preact'], | ||
| url: `${EXTERNAL_BUNDLE_PREFIX}/react.lynx.bundle`, | ||
| background: { sectionPath: 'ReactLynx' }, | ||
| mainThread: { sectionPath: 'ReactLynx__main-thread' }, | ||
| async: false, | ||
| }, | ||
| './App.js': { | ||
| libraryName: 'CompLib', | ||
| url: `${EXTERNAL_BUNDLE_PREFIX}/comp-lib.lynx.bundle`, | ||
| background: { sectionPath: 'CompLib' }, | ||
| mainThread: { sectionPath: 'CompLib__main-thread' }, | ||
| async: false, | ||
| }, | ||
| }, | ||
| }), | ||
| ], | ||
| }, | ||
| }, | ||
| plugins: [ | ||
| pluginReactLynx(), | ||
| pluginQRCode({ | ||
| schema(url) { | ||
| // We use `?fullscreen=true` to open the page in LynxExplorer in full screen mode | ||
| return `${url}?fullscreen=true`; | ||
| }, | ||
| }), | ||
| ], | ||
| environments: { | ||
| web: {}, | ||
| lynx: { | ||
| performance: { | ||
| profile: enableBundleAnalysis, | ||
| }, | ||
| }, | ||
| }, | ||
| output: { | ||
| filenameHash: 'contenthash:8', | ||
| cleanDistPath: false, | ||
| }, | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| { | ||
| "name": "@lynx-js/example-react-externals", | ||
| "version": "0.0.0", | ||
| "private": true, | ||
| "type": "module", | ||
| "scripts": { | ||
| "build": "rspeedy build", | ||
| "build:comp-lib": "rslib build --config rslib-comp-lib.config.ts", | ||
| "build:reactlynx": "rslib build --config rslib-reactlynx.config.ts", | ||
| "dev": "rspeedy dev" | ||
| }, | ||
|
upupming marked this conversation as resolved.
|
||
| "dependencies": { | ||
| "@lynx-js/react": "workspace:*" | ||
| }, | ||
| "devDependencies": { | ||
| "@lynx-js/externals-loading-webpack-plugin": "workspace:*", | ||
| "@lynx-js/lynx-bundle-rslib-config": "workspace:*", | ||
| "@lynx-js/preact-devtools": "^5.0.1-cf9aef5", | ||
| "@lynx-js/qrcode-rsbuild-plugin": "workspace:*", | ||
| "@lynx-js/react-alias-rsbuild-plugin": "workspace:*", | ||
| "@lynx-js/react-rsbuild-plugin": "workspace:*", | ||
| "@lynx-js/react-webpack-plugin": "workspace:*", | ||
| "@lynx-js/rspeedy": "workspace:*", | ||
| "@lynx-js/types": "3.4.11", | ||
| "@types/react": "^18.3.25" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import { createRequire } from 'node:module'; | ||
| import path from 'node:path'; | ||
|
|
||
| import { | ||
| LAYERS, | ||
| defineExternalBundleRslibConfig, | ||
| } from '@lynx-js/lynx-bundle-rslib-config'; | ||
| import { pluginReactAlias } from '@lynx-js/react-alias-rsbuild-plugin'; | ||
| import { ReactWebpackPlugin } from '@lynx-js/react-webpack-plugin'; | ||
|
|
||
| const require = createRequire(import.meta.url); | ||
| const reactLynxDir = path.dirname( | ||
| require.resolve('@lynx-js/react/package.json'), | ||
| ); | ||
|
|
||
| export default defineExternalBundleRslibConfig({ | ||
| id: 'comp-lib', | ||
| tools: { | ||
| rspack: { | ||
| module: { | ||
| rules: [ | ||
| { | ||
| test: /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/, | ||
| issuerLayer: LAYERS.BACKGROUND, | ||
| loader: ReactWebpackPlugin.loaders.BACKGROUND, | ||
| }, | ||
| { | ||
| test: /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/, | ||
| issuerLayer: LAYERS.MAIN_THREAD, | ||
| loader: ReactWebpackPlugin.loaders.MAIN_THREAD, | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| }, | ||
| source: { | ||
| entry: { | ||
| 'CompLib': './external-bundle/CompLib.tsx', | ||
| }, | ||
| define: { | ||
| '__DEV__': 'false', | ||
| 'process.env.NODE_ENV': '"production"', | ||
| '__FIRST_SCREEN_SYNC_TIMING__': '"immediately"', | ||
| '__ENABLE_SSR__': 'false', | ||
| '__PROFILE__': 'false', | ||
| '__EXTRACT_STR__': 'false', | ||
| }, | ||
| }, | ||
| plugins: [ | ||
| pluginReactAlias({ | ||
| LAYERS, | ||
| rootPath: reactLynxDir, | ||
| }), | ||
| ], | ||
| output: { | ||
| cleanDistPath: false, | ||
| dataUriLimit: Number.POSITIVE_INFINITY, | ||
| externals: { | ||
| '@lynx-js/react': ['ReactLynx', 'React'], | ||
| '@lynx-js/react/internal': ['ReactLynx', 'ReactInternal'], | ||
| '@lynx-js/react/experimental/lazy/import': [ | ||
| 'ReactLynx', | ||
| 'ReactLazyImport', | ||
| ], | ||
| '@lynx-js/react/legacy-react-runtime': [ | ||
| 'ReactLynx', | ||
| 'ReactLegacyRuntime', | ||
| ], | ||
| '@lynx-js/react/runtime-components': ['ReactLynx', 'ReactComponents'], | ||
| '@lynx-js/react/worklet-runtime/bindings': [ | ||
| 'ReactLynx', | ||
| 'ReactWorkletRuntime', | ||
| ], | ||
| '@lynx-js/react/debug': ['ReactLynx', 'ReactDebug'], | ||
| 'preact': ['ReactLynx', 'Preact'], | ||
| }, | ||
| minify: false, | ||
| }, | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import { createRequire } from 'node:module'; | ||
| import path from 'node:path'; | ||
|
|
||
| import { | ||
| LAYERS, | ||
| defineExternalBundleRslibConfig, | ||
| } from '@lynx-js/lynx-bundle-rslib-config'; | ||
| import { pluginReactAlias } from '@lynx-js/react-alias-rsbuild-plugin'; | ||
| import { ReactWebpackPlugin } from '@lynx-js/react-webpack-plugin'; | ||
|
|
||
| const require = createRequire(import.meta.url); | ||
| const reactLynxDir = path.dirname( | ||
| require.resolve('@lynx-js/react/package.json'), | ||
| ); | ||
| export default defineExternalBundleRslibConfig({ | ||
| id: 'react', | ||
| tools: { | ||
| rspack: { | ||
| module: { | ||
| rules: [ | ||
| { | ||
| test: /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/, | ||
| issuerLayer: LAYERS.BACKGROUND, | ||
| loader: ReactWebpackPlugin.loaders.BACKGROUND, | ||
| }, | ||
| { | ||
| issuerLayer: LAYERS.MAIN_THREAD, | ||
| test: /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/, | ||
| loader: ReactWebpackPlugin.loaders.MAIN_THREAD, | ||
| }, | ||
| ], | ||
| }, | ||
|
upupming marked this conversation as resolved.
|
||
| }, | ||
| }, | ||
| source: { | ||
| entry: { | ||
| 'ReactLynx': './external-bundle/ReactLynx.ts', | ||
| }, | ||
| define: { | ||
| '__DEV__': 'false', | ||
| 'process.env.NODE_ENV': '"production"', | ||
| '__FIRST_SCREEN_SYNC_TIMING__': '"immediately"', | ||
| '__ENABLE_SSR__': 'false', | ||
| '__PROFILE__': 'false', | ||
| '__EXTRACT_STR__': 'false', | ||
| }, | ||
| }, | ||
| plugins: [ | ||
| pluginReactAlias({ | ||
| LAYERS, | ||
| rootPath: reactLynxDir, | ||
| }), | ||
| ], | ||
| output: { | ||
| cleanDistPath: false, | ||
| minify: false, | ||
| }, | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.