Skip to content

Commit d4c37b6

Browse files
committed
feat: init @lynx-js/lynx-bundle-rslib-config
1 parent e1a9493 commit d4c37b6

File tree

20 files changed

+880
-6
lines changed

20 files changed

+880
-6
lines changed

.changeset/stale-rings-tan.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
"@lynx-js/lynx-bundle-rslib-config": patch
3+
---
4+
5+
Add `@lynx-js/lynx-bundle-rslib-config` for bundling Lynx bundle with [Rslib](https://rslib.rs/):
6+
7+
```js
8+
// rslib.config.js
9+
import {
10+
defineExternalBundleRslibConfig,
11+
LAYERS,
12+
} from '@lynx-js/lynx-bundle-rslib-config';
13+
14+
export default defineExternalBundleRslibConfig({
15+
id: 'utils-lib',
16+
source: {
17+
entry: {
18+
utils: './src/utils.ts',
19+
},
20+
},
21+
});
22+
```
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<h2 align="center">@lynx-js/lynx-bundle-rslib-config</h2>
2+
3+
The package `@lynx-js/lynx-bundle-rslib-config` provides the configurations for bundling Lynx bundle with [Rslib](https://rslib.rs/).
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* Config file for API Extractor. For more info, please visit: https://api-extractor.com
3+
*/
4+
{
5+
"extends": "../../../api-extractor.json",
6+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
## API Report File for "@lynx-js/lynx-bundle-rslib-config"
2+
3+
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
4+
5+
```ts
6+
7+
import type { BannerPlugin } from 'webpack';
8+
import type { Compiler } from 'webpack';
9+
import type { LibConfig } from '@rslib/core';
10+
import type { RslibConfig } from '@rslib/core';
11+
12+
// Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@lynx-js/lynx-bundle-rslib-config" does not have an export "LibConfig"
13+
//
14+
// @public
15+
export const defaultExternalBundleLibConfig: LibConfig;
16+
17+
// Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@lynx-js/lynx-bundle-rslib-config" does not have an export "LibConfig"
18+
//
19+
// @public
20+
export const defaultExternalBundleRsbuildConfig: RslibConfig['lib'][0];
21+
22+
// @public
23+
export function defineExternalBundleRslibConfig(userLibConfig: LibConfig): RslibConfig;
24+
25+
// @public
26+
export const LAYERS: {
27+
readonly BACKGROUND: "background";
28+
readonly MAIN_THREAD: "main-thread";
29+
};
30+
31+
// Warning: (ae-missing-release-tag) "LazyBundleWebpackPlugin" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
32+
//
33+
// @public (undocumented)
34+
export class LazyBundleWebpackPlugin {
35+
// Warning: (ae-forgotten-export) The symbol "LazyBundleWebpackPluginOptions" needs to be exported by the entry point index.d.ts
36+
constructor(options: LazyBundleWebpackPluginOptions);
37+
// (undocumented)
38+
apply(compiler: Compiler): void;
39+
}
40+
41+
// Warning: (ae-missing-release-tag) "MainThreadRuntimeWrapperWebpackPlugin" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
42+
//
43+
// @public (undocumented)
44+
export class MainThreadRuntimeWrapperWebpackPlugin {
45+
// Warning: (ae-forgotten-export) The symbol "MainThreadRuntimeWrapperWebpackPluginOptions" needs to be exported by the entry point index.d.ts
46+
constructor(options?: Partial<MainThreadRuntimeWrapperWebpackPluginOptions>);
47+
// (undocumented)
48+
apply(compiler: Compiler): void;
49+
}
50+
51+
```
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"name": "@lynx-js/lynx-bundle-rslib-config",
3+
"version": "0.0.0",
4+
"description": "The rsbuild config for building Lynx bundle",
5+
"keywords": [
6+
"Rsbuild",
7+
"Rspeedy",
8+
"Lynx",
9+
"Rslib"
10+
],
11+
"repository": {
12+
"type": "git",
13+
"url": "https://github.com/lynx-family/lynx-stack.git",
14+
"directory": "packages/rspeedy/lynx-bundle-rslib-config"
15+
},
16+
"license": "Apache-2.0",
17+
"author": {
18+
"name": "Hengchang Lu",
19+
"email": "[email protected]"
20+
},
21+
"type": "module",
22+
"exports": {
23+
".": {
24+
"types": "./lib/index.d.ts",
25+
"default": "./lib/index.js"
26+
}
27+
},
28+
"files": [
29+
"lib",
30+
"!lib/**/*.js.map",
31+
"CHANGELOG.md",
32+
"README.md"
33+
],
34+
"scripts": {
35+
"api-extractor": "api-extractor run --verbose",
36+
"test": "vitest"
37+
},
38+
"dependencies": {
39+
"@lynx-js/runtime-wrapper-webpack-plugin": "workspace:*",
40+
"@lynx-js/tasm": "0.0.19"
41+
},
42+
"devDependencies": {
43+
"@rslib/core": "^0.15.0",
44+
"vitest": "^3.2.4",
45+
"webpack": "^5.102.0"
46+
},
47+
"engines": {
48+
"node": ">=18"
49+
}
50+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright 2025 The Lynx Authors. All rights reserved.
2+
// Licensed under the Apache License Version 2.0 that can be found in the
3+
// LICENSE file in the root directory of this source tree.
4+
5+
/**
6+
* @packageDocumentation
7+
*
8+
* `@lynx-js/lynx-bundle-rslib-config` is the package that provides the configurations for bundling Lynx bundle with {@link https://rslib.rs/ | Rslib}.
9+
*
10+
* 1. Install the package:
11+
*
12+
* ```bash
13+
* pnpm add @lynx-js/lynx-bundle-rslib-config @rslib/core -D
14+
* ```
15+
*
16+
* 2. Add the following code to `rslib.config.ts`:
17+
*
18+
* ```ts
19+
* import { defineExternalBundleRslibConfig } from '@lynx-js/lynx-bundle-rslib-config'
20+
*
21+
* export default defineExternalBundleRslibConfig({
22+
* id: 'my-utils',
23+
* source: {
24+
* entry: {
25+
* utils: './src/utils.ts'
26+
* }
27+
* }
28+
* })
29+
* ```
30+
*
31+
* 3. Run the command `pnpm rslib build` and you will get the `my-utils.lynx.bundle` in the `dist` directory. You can upload the bundle to CDN or server.
32+
*
33+
* 4. Finally, you can fetch and load the external bundle through:
34+
*
35+
* ```js
36+
* const bundleUrl = 'http://cdn.com/my-utils.lynx.bundle'
37+
* lynx.fetchBundle(bundleUrl).wait(3) // timeout is 3s
38+
*
39+
* if (__BACKGROUND__) {
40+
* const utils = lynx.loadScript('utils', { bundleName: bundleUrl })
41+
* } else {
42+
* const utils = lynx.loadScript('utils__main-thread', { bundleName: bundleUrl })
43+
* }
44+
* ```
45+
*
46+
* For more detail, please refer to the {@link defineExternalBundleRslibConfig}.
47+
*/
48+
export {
49+
defineExternalBundleRslibConfig,
50+
defaultExternalBundleLibConfig,
51+
defaultExternalBundleRsbuildConfig,
52+
LAYERS,
53+
} from './lynxBundleRslibConfig.js'
54+
55+
export { LazyBundleWebpackPlugin } from './webpack/LazyBundleWebpackPlugin.js'
56+
export { MainThreadRuntimeWrapperWebpackPlugin } from './webpack/MainThreadRuntimeWrapperWebpackPlugin.js'

0 commit comments

Comments
 (0)