@lynx-js/lynx-bundle-rslib-config-canary 0.0.1 → 0.0.2-canary-20251222-4d689a71
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# @lynx-js/lynx-bundle-rslib-config
|
|
2
2
|
|
|
3
|
+
## 0.0.2-canary-20251222035207-4d689a7194cc9b431e6055e87792c1961a44af4d
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Introduce `@lynx-js/externals-loading-webpack-plugin`. It will help you to load externals built by `@lynx-js/lynx-bundle-rslib-config`. ([#1924](https://github.com/lynx-family/lynx-stack/pull/1924))
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
// webpack.config.js
|
|
11
|
+
import { ExternalsLoadingPlugin } from "@lynx-js/externals-loading-webpack-plugin";
|
|
12
|
+
|
|
13
|
+
export default {
|
|
14
|
+
plugins: [
|
|
15
|
+
new ExternalsLoadingPlugin({
|
|
16
|
+
mainThreadLayer: "main-thread",
|
|
17
|
+
backgroundLayer: "background",
|
|
18
|
+
externals: {
|
|
19
|
+
lodash: {
|
|
20
|
+
url: "http://lodash.lynx.bundle",
|
|
21
|
+
background: { sectionPath: "background" },
|
|
22
|
+
mainThread: { sectionPath: "main-thread" },
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
}),
|
|
26
|
+
],
|
|
27
|
+
};
|
|
28
|
+
```
|
|
29
|
+
|
|
3
30
|
## 0.0.1
|
|
4
31
|
|
|
5
32
|
### Patch Changes
|
|
@@ -8,14 +35,14 @@
|
|
|
8
35
|
|
|
9
36
|
```js
|
|
10
37
|
// rslib.config.js
|
|
11
|
-
import { defineExternalBundleRslibConfig } from
|
|
38
|
+
import { defineExternalBundleRslibConfig } from "@lynx-js/lynx-bundle-rslib-config";
|
|
12
39
|
|
|
13
40
|
export default defineExternalBundleRslibConfig({
|
|
14
|
-
id:
|
|
41
|
+
id: "utils-lib",
|
|
15
42
|
source: {
|
|
16
43
|
entry: {
|
|
17
|
-
utils:
|
|
44
|
+
utils: "./src/utils.ts",
|
|
18
45
|
},
|
|
19
46
|
},
|
|
20
|
-
})
|
|
47
|
+
});
|
|
21
48
|
```
|
|
@@ -27,6 +27,14 @@ export declare const LAYERS: {
|
|
|
27
27
|
* @public
|
|
28
28
|
*/
|
|
29
29
|
export declare const defaultExternalBundleLibConfig: LibConfig;
|
|
30
|
+
export type Externals = Record<string, string | string[]>;
|
|
31
|
+
export type LibOutputConfig = Required<LibConfig>['output'];
|
|
32
|
+
export interface OutputConfig extends LibOutputConfig {
|
|
33
|
+
externals?: Externals;
|
|
34
|
+
}
|
|
35
|
+
export interface ExternalBundleLibConfig extends LibConfig {
|
|
36
|
+
output?: OutputConfig;
|
|
37
|
+
}
|
|
30
38
|
/**
|
|
31
39
|
* Get the rslib config for building Lynx external bundles.
|
|
32
40
|
*
|
|
@@ -97,4 +105,4 @@ export declare const defaultExternalBundleLibConfig: LibConfig;
|
|
|
97
105
|
*
|
|
98
106
|
* Then you can use `lynx.loadScript('utils', { bundleName: 'utils-lib-bundle-url' })` in background thread and `lynx.loadScript('utils__main-thread', { bundleName: 'utils-lib-bundle-url' })` in main-thread.
|
|
99
107
|
*/
|
|
100
|
-
export declare function defineExternalBundleRslibConfig(userLibConfig:
|
|
108
|
+
export declare function defineExternalBundleRslibConfig(userLibConfig: ExternalBundleLibConfig, encodeOptions?: EncodeOptions): RslibConfig;
|
|
@@ -54,6 +54,21 @@ export const defaultExternalBundleLibConfig = {
|
|
|
54
54
|
include: [/node_modules/],
|
|
55
55
|
},
|
|
56
56
|
};
|
|
57
|
+
function transformExternals(externals) {
|
|
58
|
+
if (!externals)
|
|
59
|
+
return {};
|
|
60
|
+
return function ({ request }, callback) {
|
|
61
|
+
if (!request)
|
|
62
|
+
return callback();
|
|
63
|
+
const libraryName = externals[request];
|
|
64
|
+
if (!libraryName)
|
|
65
|
+
return callback();
|
|
66
|
+
callback(undefined, [
|
|
67
|
+
'lynx[Symbol.for("__LYNX_EXTERNAL_GLOBAL__")]',
|
|
68
|
+
...(Array.isArray(libraryName) ? libraryName : [libraryName]),
|
|
69
|
+
], 'var');
|
|
70
|
+
};
|
|
71
|
+
}
|
|
57
72
|
/**
|
|
58
73
|
* Get the rslib config for building Lynx external bundles.
|
|
59
74
|
*
|
|
@@ -128,7 +143,13 @@ export function defineExternalBundleRslibConfig(userLibConfig, encodeOptions = {
|
|
|
128
143
|
return {
|
|
129
144
|
lib: [
|
|
130
145
|
// eslint-disable-next-line import/namespace
|
|
131
|
-
rsbuild.mergeRsbuildConfig(defaultExternalBundleLibConfig,
|
|
146
|
+
rsbuild.mergeRsbuildConfig(defaultExternalBundleLibConfig, {
|
|
147
|
+
...userLibConfig,
|
|
148
|
+
output: {
|
|
149
|
+
...userLibConfig.output,
|
|
150
|
+
externals: transformExternals(userLibConfig.output?.externals),
|
|
151
|
+
},
|
|
152
|
+
}),
|
|
132
153
|
],
|
|
133
154
|
plugins: [
|
|
134
155
|
externalBundleEntryRsbuildPlugin(),
|