@lynx-js/template-webpack-plugin-canary 0.6.3-canary-20250302-1abf8f01
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 +124 -0
- package/LICENSE +202 -0
- package/README.md +4 -0
- package/lib/LynxAsyncChunksRuntimeModule.d.ts +4 -0
- package/lib/LynxAsyncChunksRuntimeModule.js +30 -0
- package/lib/LynxEncodePlugin.d.ts +105 -0
- package/lib/LynxEncodePlugin.js +192 -0
- package/lib/LynxTemplatePlugin.d.ts +329 -0
- package/lib/LynxTemplatePlugin.js +486 -0
- package/lib/css/ast.d.ts +3 -0
- package/lib/css/ast.js +11 -0
- package/lib/css/cssChunksToMap.d.ts +6 -0
- package/lib/css/cssChunksToMap.js +27 -0
- package/lib/css/debundle.d.ts +1 -0
- package/lib/css/debundle.js +86 -0
- package/lib/css/encode.d.ts +17 -0
- package/lib/css/encode.js +36 -0
- package/lib/css/index.d.ts +3 -0
- package/lib/css/index.js +6 -0
- package/lib/css/plugins/index.d.ts +1 -0
- package/lib/css/plugins/index.js +5 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.js +13 -0
- package/package.json +51 -0
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
import { AsyncSeriesBailHook, AsyncSeriesWaterfallHook, SyncWaterfallHook } from '@rspack/lite-tapable';
|
|
2
|
+
import type { Asset, Compilation, Compiler } from 'webpack';
|
|
3
|
+
import type * as CSS from '@lynx-js/css-serializer';
|
|
4
|
+
import { cssChunksToMap } from './css/cssChunksToMap.js';
|
|
5
|
+
interface EncodeOptions {
|
|
6
|
+
manifest: Record<string, string | undefined>;
|
|
7
|
+
compilerOptions: Record<string, string | boolean>;
|
|
8
|
+
lepusCode: {
|
|
9
|
+
root: string | undefined;
|
|
10
|
+
lepusChunk: Record<string, string>;
|
|
11
|
+
};
|
|
12
|
+
customSections: Record<string, {
|
|
13
|
+
type?: 'lazy';
|
|
14
|
+
content: string | Record<string, unknown>;
|
|
15
|
+
}>;
|
|
16
|
+
[k: string]: unknown;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* To allow other plugins to alter the Template, this plugin executes
|
|
20
|
+
* {@link https://github.com/webpack/tapable | tapable} hooks.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```js
|
|
24
|
+
* class MyPlugin {
|
|
25
|
+
* apply(compiler) {
|
|
26
|
+
* compiler.hooks.compilation.tap("MyPlugin", (compilation) => {
|
|
27
|
+
* console.log("The compiler is starting a new compilation...");
|
|
28
|
+
*
|
|
29
|
+
* LynxTemplatePlugin.getCompilationHooks(compilation).beforeEmit.tapAsync(
|
|
30
|
+
* "MyPlugin", // <-- Set a meaningful name here for stacktraces
|
|
31
|
+
* (data, cb) => {
|
|
32
|
+
* // Manipulate the content
|
|
33
|
+
* modifyTemplate(data.template)
|
|
34
|
+
* // Tell webpack to move on
|
|
35
|
+
* cb(null, data);
|
|
36
|
+
* },
|
|
37
|
+
* );
|
|
38
|
+
* });
|
|
39
|
+
* }
|
|
40
|
+
* }
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* @public
|
|
44
|
+
*/
|
|
45
|
+
export interface TemplateHooks {
|
|
46
|
+
/**
|
|
47
|
+
* Get the real name of an async chunk. The files with the same `asyncChunkName` will be placed in the same template.
|
|
48
|
+
*
|
|
49
|
+
* @alpha
|
|
50
|
+
*/
|
|
51
|
+
asyncChunkName: SyncWaterfallHook<string | undefined | null>;
|
|
52
|
+
/**
|
|
53
|
+
* Called before the encode process. Can be used to modify the encode options.
|
|
54
|
+
*
|
|
55
|
+
* @alpha
|
|
56
|
+
*/
|
|
57
|
+
beforeEncode: AsyncSeriesWaterfallHook<{
|
|
58
|
+
encodeData: EncodeRawData;
|
|
59
|
+
filenameTemplate: string;
|
|
60
|
+
entryNames: string[];
|
|
61
|
+
}>;
|
|
62
|
+
/**
|
|
63
|
+
* Call the encode process.
|
|
64
|
+
*
|
|
65
|
+
* @alpha
|
|
66
|
+
*/
|
|
67
|
+
encode: AsyncSeriesBailHook<{
|
|
68
|
+
encodeOptions: EncodeOptions;
|
|
69
|
+
intermediate: string;
|
|
70
|
+
}, {
|
|
71
|
+
buffer: Buffer;
|
|
72
|
+
debugInfo: string;
|
|
73
|
+
}>;
|
|
74
|
+
/**
|
|
75
|
+
* Called before the template is emitted. Can be used to modify the template.
|
|
76
|
+
*
|
|
77
|
+
* @alpha
|
|
78
|
+
*/
|
|
79
|
+
beforeEmit: AsyncSeriesWaterfallHook<{
|
|
80
|
+
finalEncodeOptions: EncodeOptions;
|
|
81
|
+
debugInfo: string;
|
|
82
|
+
template: Buffer;
|
|
83
|
+
outputName: string;
|
|
84
|
+
lepus: Asset[];
|
|
85
|
+
}>;
|
|
86
|
+
/**
|
|
87
|
+
* Called after the template is emitted.
|
|
88
|
+
*
|
|
89
|
+
* @alpha
|
|
90
|
+
*/
|
|
91
|
+
afterEmit: AsyncSeriesWaterfallHook<{
|
|
92
|
+
outputName: string;
|
|
93
|
+
}>;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The options for LynxTemplatePlugin
|
|
97
|
+
*
|
|
98
|
+
* @public
|
|
99
|
+
*/
|
|
100
|
+
export interface LynxTemplatePluginOptions {
|
|
101
|
+
/**
|
|
102
|
+
* The file to write the template to.
|
|
103
|
+
* Supports subdirectories eg: `assets/template.js`.
|
|
104
|
+
* [name] will be replaced by the entry name.
|
|
105
|
+
* Supports a function to generate the name.
|
|
106
|
+
*
|
|
107
|
+
* @defaultValue `'[name].bundle'`
|
|
108
|
+
*/
|
|
109
|
+
filename?: string | ((entryName: string) => string);
|
|
110
|
+
/**
|
|
111
|
+
* The filename of the lazy bundle.
|
|
112
|
+
*
|
|
113
|
+
* @defaultValue `'async/[name].[fullhash].bundle'`
|
|
114
|
+
*/
|
|
115
|
+
lazyBundleFilename?: string;
|
|
116
|
+
/**
|
|
117
|
+
* {@inheritdoc @lynx-js/rspeedy#DistPath.intermediate}
|
|
118
|
+
*/
|
|
119
|
+
intermediate?: string;
|
|
120
|
+
/**
|
|
121
|
+
* List all entries which should be injected
|
|
122
|
+
*
|
|
123
|
+
* @defaultValue `'all'`
|
|
124
|
+
*/
|
|
125
|
+
chunks?: 'all' | string[];
|
|
126
|
+
/**
|
|
127
|
+
* List all entries which should not be injected
|
|
128
|
+
*
|
|
129
|
+
* @defaultValue `[]`
|
|
130
|
+
*/
|
|
131
|
+
excludeChunks?: string[];
|
|
132
|
+
/**
|
|
133
|
+
* {@inheritdoc @lynx-js/react-rsbuild-plugin#PluginReactLynxOptions.customCSSInheritanceList}
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
*
|
|
137
|
+
* By setting `customCSSInheritanceList: ['direction', 'overflow']`, only the `direction` and `overflow` properties are inheritable.
|
|
138
|
+
*
|
|
139
|
+
* ```js
|
|
140
|
+
* import { defineConfig } from '@lynx-js/rspeedy'
|
|
141
|
+
*
|
|
142
|
+
* export default defineConfig({
|
|
143
|
+
* plugins: [
|
|
144
|
+
* pluginReactLynx({
|
|
145
|
+
* enableCSSInheritance: true,
|
|
146
|
+
* customCSSInheritanceList: ['direction', 'overflow']
|
|
147
|
+
* }),
|
|
148
|
+
* ],
|
|
149
|
+
* }
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
customCSSInheritanceList: string[] | undefined;
|
|
153
|
+
/**
|
|
154
|
+
* {@inheritdoc @lynx-js/react-rsbuild-plugin#PluginReactLynxOptions.debugInfoOutside}
|
|
155
|
+
*/
|
|
156
|
+
debugInfoOutside: boolean;
|
|
157
|
+
/**
|
|
158
|
+
* {@inheritdoc @lynx-js/react-rsbuild-plugin#PluginReactLynxOptions.defaultDisplayLinear}
|
|
159
|
+
*/
|
|
160
|
+
defaultDisplayLinear: boolean;
|
|
161
|
+
/**
|
|
162
|
+
* Declare the current dsl to the encoder.
|
|
163
|
+
*
|
|
164
|
+
* @public
|
|
165
|
+
*/
|
|
166
|
+
dsl?: 'tt' | 'react' | 'react_nodiff';
|
|
167
|
+
/**
|
|
168
|
+
* {@inheritdoc @lynx-js/react-rsbuild-plugin#PluginReactLynxOptions.enableAccessibilityElement}
|
|
169
|
+
*/
|
|
170
|
+
enableAccessibilityElement: boolean;
|
|
171
|
+
/**
|
|
172
|
+
* {@inheritdoc @lynx-js/react-rsbuild-plugin#PluginReactLynxOptions.enableICU}
|
|
173
|
+
*/
|
|
174
|
+
enableICU: boolean;
|
|
175
|
+
/**
|
|
176
|
+
* Use Android View level APIs and system implementations.
|
|
177
|
+
*/
|
|
178
|
+
enableA11y: boolean;
|
|
179
|
+
/**
|
|
180
|
+
* {@inheritdoc @lynx-js/react-rsbuild-plugin#PluginReactLynxOptions.enableCSSInheritance}
|
|
181
|
+
*/
|
|
182
|
+
enableCSSInheritance: boolean;
|
|
183
|
+
/**
|
|
184
|
+
* {@inheritdoc @lynx-js/react-rsbuild-plugin#PluginReactLynxOptions.enableCSSInvalidation}
|
|
185
|
+
*/
|
|
186
|
+
enableCSSInvalidation: boolean;
|
|
187
|
+
/**
|
|
188
|
+
* {@inheritdoc @lynx-js/react-rsbuild-plugin#PluginReactLynxOptions.enableCSSSelector}
|
|
189
|
+
*/
|
|
190
|
+
enableCSSSelector: boolean;
|
|
191
|
+
/**
|
|
192
|
+
* {@inheritdoc @lynx-js/react-rsbuild-plugin#PluginReactLynxOptions.enableNewGesture}
|
|
193
|
+
*/
|
|
194
|
+
enableNewGesture: boolean;
|
|
195
|
+
/**
|
|
196
|
+
* {@inheritdoc @lynx-js/react-rsbuild-plugin#PluginReactLynxOptions.enableParallelElement}
|
|
197
|
+
*/
|
|
198
|
+
enableParallelElement?: boolean;
|
|
199
|
+
/**
|
|
200
|
+
* {@inheritdoc @lynx-js/react-rsbuild-plugin#PluginReactLynxOptions.enableRemoveCSSScope}
|
|
201
|
+
*/
|
|
202
|
+
enableRemoveCSSScope: boolean;
|
|
203
|
+
/**
|
|
204
|
+
* {@inheritdoc @lynx-js/react-rsbuild-plugin#PluginReactLynxOptions.pipelineSchedulerConfig}
|
|
205
|
+
*/
|
|
206
|
+
pipelineSchedulerConfig: number;
|
|
207
|
+
/**
|
|
208
|
+
* {@inheritdoc @lynx-js/react-rsbuild-plugin#PluginReactLynxOptions.removeDescendantSelectorScope}
|
|
209
|
+
*/
|
|
210
|
+
removeDescendantSelectorScope: boolean;
|
|
211
|
+
/**
|
|
212
|
+
* {@inheritdoc @lynx-js/react-rsbuild-plugin#PluginReactLynxOptions.targetSdkVersion}
|
|
213
|
+
*/
|
|
214
|
+
targetSdkVersion: string;
|
|
215
|
+
/**
|
|
216
|
+
* `encodeBinary` is used to specify the binary of the template encoder.
|
|
217
|
+
*
|
|
218
|
+
* @defaultValue `napi`
|
|
219
|
+
*
|
|
220
|
+
* @public
|
|
221
|
+
*/
|
|
222
|
+
encodeBinary?: 'napi' | 'wasm';
|
|
223
|
+
/**
|
|
224
|
+
* {@inheritdoc @lynx-js/react-rsbuild-plugin#PluginReactLynxOptions.experimental_isLazyBundle}
|
|
225
|
+
*
|
|
226
|
+
* @alpha
|
|
227
|
+
*/
|
|
228
|
+
experimental_isLazyBundle?: boolean;
|
|
229
|
+
/**
|
|
230
|
+
* plugins passed to parser
|
|
231
|
+
*/
|
|
232
|
+
cssPlugins: CSS.Plugin[];
|
|
233
|
+
}
|
|
234
|
+
interface EncodeRawData {
|
|
235
|
+
compilerOptions: {
|
|
236
|
+
enableCSSSelector: boolean;
|
|
237
|
+
targetSdkVersion: string;
|
|
238
|
+
[k: string]: string | boolean;
|
|
239
|
+
};
|
|
240
|
+
/**
|
|
241
|
+
* main-thread
|
|
242
|
+
*/
|
|
243
|
+
lepusCode: {
|
|
244
|
+
root: Asset | undefined;
|
|
245
|
+
chunks: Asset[];
|
|
246
|
+
};
|
|
247
|
+
/**
|
|
248
|
+
* background thread
|
|
249
|
+
*/
|
|
250
|
+
manifest: Record<string, string>;
|
|
251
|
+
css: {
|
|
252
|
+
chunks: Asset[];
|
|
253
|
+
} & ReturnType<typeof cssChunksToMap>;
|
|
254
|
+
customSections: Record<string, {
|
|
255
|
+
type?: 'lazy';
|
|
256
|
+
content: string | Record<string, unknown>;
|
|
257
|
+
}>;
|
|
258
|
+
sourceContent: {
|
|
259
|
+
dsl: string;
|
|
260
|
+
appType: string;
|
|
261
|
+
config: Record<string, unknown>;
|
|
262
|
+
};
|
|
263
|
+
[k: string]: unknown;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* LynxTemplatePlugin
|
|
267
|
+
*
|
|
268
|
+
* @public
|
|
269
|
+
*/
|
|
270
|
+
export declare class LynxTemplatePlugin {
|
|
271
|
+
private options?;
|
|
272
|
+
constructor(options?: LynxTemplatePluginOptions | undefined);
|
|
273
|
+
/**
|
|
274
|
+
* Returns all public hooks of the Lynx template webpack plugin for the given compilation
|
|
275
|
+
*/
|
|
276
|
+
static getLynxTemplatePluginHooks(compilation: Compilation): TemplateHooks;
|
|
277
|
+
/**
|
|
278
|
+
* `defaultOptions` is the default options that the {@link LynxTemplatePlugin} uses.
|
|
279
|
+
*
|
|
280
|
+
* @example
|
|
281
|
+
* `defaultOptions` can be used to change part of the option and keep others as the default value.
|
|
282
|
+
*
|
|
283
|
+
* ```js
|
|
284
|
+
* // webpack.config.js
|
|
285
|
+
* import { LynxTemplatePlugin } from '@lynx-js/template-webpack-plugin'
|
|
286
|
+
* export default {
|
|
287
|
+
* plugins: [
|
|
288
|
+
* new LynxTemplatePlugin({
|
|
289
|
+
* ...LynxTemplatePlugin.defaultOptions,
|
|
290
|
+
* enableRemoveCSSScope: true,
|
|
291
|
+
* }),
|
|
292
|
+
* ],
|
|
293
|
+
* }
|
|
294
|
+
* ```
|
|
295
|
+
*
|
|
296
|
+
* @public
|
|
297
|
+
*/
|
|
298
|
+
static defaultOptions: Readonly<Required<LynxTemplatePluginOptions>>;
|
|
299
|
+
/**
|
|
300
|
+
* Convert the css chunks to css map.
|
|
301
|
+
*
|
|
302
|
+
* @param cssChunks - The CSS chunks content.
|
|
303
|
+
* @param options - The encode options.
|
|
304
|
+
* @returns The CSS map and css source.
|
|
305
|
+
*
|
|
306
|
+
* @example
|
|
307
|
+
* ```
|
|
308
|
+
* (console.log(await convertCSSChunksToMap(
|
|
309
|
+
* '.red { color: red; }',
|
|
310
|
+
* {
|
|
311
|
+
* targetSdkVersion: '3.2',
|
|
312
|
+
* enableCSSSelector: true,
|
|
313
|
+
* },
|
|
314
|
+
* )));
|
|
315
|
+
* ```
|
|
316
|
+
*/
|
|
317
|
+
static convertCSSChunksToMap(cssChunks: string[], plugins: CSS.Plugin[]): {
|
|
318
|
+
cssMap: Record<string, CSS.LynxStyleNode[]>;
|
|
319
|
+
cssSource: Record<string, string>;
|
|
320
|
+
};
|
|
321
|
+
/**
|
|
322
|
+
* The entry point of a webpack plugin.
|
|
323
|
+
* @param compiler - the webpack compiler
|
|
324
|
+
*/
|
|
325
|
+
apply(compiler: Compiler): void;
|
|
326
|
+
}
|
|
327
|
+
export declare function isDebug(): boolean;
|
|
328
|
+
export declare function isRsdoctor(): boolean;
|
|
329
|
+
export {};
|