@lynx-js/rspeedy 0.8.2
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 +208 -0
- package/LICENSE +202 -0
- package/README.md +32 -0
- package/bin/rspeedy.js +33 -0
- package/client/hmr/WebSocketClient.js +65 -0
- package/client.d.ts +5 -0
- package/lib/api.d.ts +46 -0
- package/lib/api.js +2 -0
- package/lib/cli/build.d.ts +4 -0
- package/lib/cli/build.js +32 -0
- package/lib/cli/commands.d.ts +5 -0
- package/lib/cli/commands.js +45 -0
- package/lib/cli/dev.d.ts +4 -0
- package/lib/cli/dev.js +75 -0
- package/lib/cli/exit.d.ts +1 -0
- package/lib/cli/exit.js +51 -0
- package/lib/cli/inspect.d.ts +8 -0
- package/lib/cli/inspect.js +30 -0
- package/lib/cli/main.d.ts +1 -0
- package/lib/cli/main.js +39 -0
- package/lib/cli/preview.d.ts +4 -0
- package/lib/cli/preview.js +31 -0
- package/lib/cli/start.d.ts +6 -0
- package/lib/cli/start.js +88 -0
- package/lib/config/defaults.d.ts +2 -0
- package/lib/config/defaults.js +32 -0
- package/lib/config/defineConfig.d.ts +22 -0
- package/lib/config/defineConfig.js +24 -0
- package/lib/config/dev/client.d.ts +15 -0
- package/lib/config/dev/client.js +2 -0
- package/lib/config/dev/index.d.ts +133 -0
- package/lib/config/dev/index.js +2 -0
- package/lib/config/index.d.ts +172 -0
- package/lib/config/index.js +2 -0
- package/lib/config/loadConfig.d.ts +50 -0
- package/lib/config/loadConfig.js +98 -0
- package/lib/config/output/css-modules.d.ts +84 -0
- package/lib/config/output/css-modules.js +2 -0
- package/lib/config/output/dist-path.d.ts +68 -0
- package/lib/config/output/dist-path.js +2 -0
- package/lib/config/output/filename.d.ts +167 -0
- package/lib/config/output/filename.js +2 -0
- package/lib/config/output/index.d.ts +320 -0
- package/lib/config/output/index.js +2 -0
- package/lib/config/output/minify.d.ts +80 -0
- package/lib/config/output/minify.js +2 -0
- package/lib/config/output/source-map.d.ts +68 -0
- package/lib/config/output/source-map.js +2 -0
- package/lib/config/performance/chunk-split.d.ts +192 -0
- package/lib/config/performance/chunk-split.js +2 -0
- package/lib/config/performance/index.d.ts +50 -0
- package/lib/config/performance/index.js +2 -0
- package/lib/config/rsbuild/entry.d.ts +3 -0
- package/lib/config/rsbuild/entry.js +31 -0
- package/lib/config/rsbuild/index.d.ts +4 -0
- package/lib/config/rsbuild/index.js +70 -0
- package/lib/config/server/index.d.ts +47 -0
- package/lib/config/server/index.js +2 -0
- package/lib/config/source/decorators.d.ts +43 -0
- package/lib/config/source/decorators.js +2 -0
- package/lib/config/source/entry.d.ts +84 -0
- package/lib/config/source/entry.js +2 -0
- package/lib/config/source/index.d.ts +474 -0
- package/lib/config/source/index.js +2 -0
- package/lib/config/source/transformImport.d.ts +106 -0
- package/lib/config/source/transformImport.js +2 -0
- package/lib/config/tools/css-extract.d.ts +72 -0
- package/lib/config/tools/css-extract.js +2 -0
- package/lib/config/tools/css-loader.d.ts +130 -0
- package/lib/config/tools/css-loader.js +2 -0
- package/lib/config/tools/index.d.ts +170 -0
- package/lib/config/tools/index.js +2 -0
- package/lib/config/validate.d.ts +4 -0
- package/lib/config/validate.js +28962 -0
- package/lib/create-rspeedy.d.ts +45 -0
- package/lib/create-rspeedy.js +48 -0
- package/lib/debug.d.ts +3 -0
- package/lib/debug.js +25 -0
- package/lib/index.d.ts +45 -0
- package/lib/index.js +10 -0
- package/lib/plugins/api.plugin.d.ts +3 -0
- package/lib/plugins/api.plugin.js +25 -0
- package/lib/plugins/chunkLoading.plugin.d.ts +2 -0
- package/lib/plugins/chunkLoading.plugin.js +30 -0
- package/lib/plugins/dev.plugin.d.ts +5 -0
- package/lib/plugins/dev.plugin.js +130 -0
- package/lib/plugins/index.d.ts +3 -0
- package/lib/plugins/index.js +49 -0
- package/lib/plugins/inspect.plugin.d.ts +4 -0
- package/lib/plugins/inspect.plugin.js +39 -0
- package/lib/plugins/minify.plugin.d.ts +3 -0
- package/lib/plugins/minify.plugin.js +89 -0
- package/lib/plugins/optimization.plugin.d.ts +2 -0
- package/lib/plugins/optimization.plugin.js +31 -0
- package/lib/plugins/output.plugin.d.ts +3 -0
- package/lib/plugins/output.plugin.js +34 -0
- package/lib/plugins/resolve.plugin.d.ts +2 -0
- package/lib/plugins/resolve.plugin.js +38 -0
- package/lib/plugins/rsdoctor.plugin.d.ts +3 -0
- package/lib/plugins/rsdoctor.plugin.js +41 -0
- package/lib/plugins/sourcemap.plugin.d.ts +2 -0
- package/lib/plugins/sourcemap.plugin.js +84 -0
- package/lib/plugins/stats.plugin.d.ts +2 -0
- package/lib/plugins/stats.plugin.js +20 -0
- package/lib/plugins/swc.plugin.d.ts +2 -0
- package/lib/plugins/swc.plugin.js +21 -0
- package/lib/plugins/target.plugin.d.ts +2 -0
- package/lib/plugins/target.plugin.js +12 -0
- package/lib/utils/getESVersionTarget.d.ts +1 -0
- package/lib/utils/getESVersionTarget.js +7 -0
- package/lib/utils/is-ci.d.ts +1 -0
- package/lib/utils/is-ci.js +7 -0
- package/lib/version.d.ts +4 -0
- package/lib/version.js +15 -0
- package/lib/webpack/CompilationIdPlugin.d.ts +4 -0
- package/lib/webpack/CompilationIdPlugin.js +20 -0
- package/lib/webpack/EvalSourceMapDevToolPlugin.d.ts +9 -0
- package/lib/webpack/EvalSourceMapDevToolPlugin.js +15 -0
- package/lib/webpack/ProvidePlugin.d.ts +9 -0
- package/lib/webpack/ProvidePlugin.js +15 -0
- package/lib/webpack/SourceMapDevToolPlugin.d.ts +9 -0
- package/lib/webpack/SourceMapDevToolPlugin.js +15 -0
- package/package.json +83 -0
- package/register/data.d.ts +9 -0
- package/register/hooks.js +146 -0
- package/register/index.d.ts +4 -0
- package/register/index.js +47 -0
|
@@ -0,0 +1,474 @@
|
|
|
1
|
+
import type { Rspack } from '@rsbuild/core';
|
|
2
|
+
import type { Decorators } from './decorators.js';
|
|
3
|
+
import type { Entry } from './entry.js';
|
|
4
|
+
import type { TransformImport } from './transformImport.js';
|
|
5
|
+
/**
|
|
6
|
+
* {@inheritdoc Config.source}
|
|
7
|
+
*
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export interface Source {
|
|
11
|
+
/**
|
|
12
|
+
* Create aliases to `import` or `require` certain modules more easily.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
*
|
|
16
|
+
* A trailing `$` can also be added to the given object's keys to signify an exact match:
|
|
17
|
+
*
|
|
18
|
+
* ```js
|
|
19
|
+
* import { defineConfig } from '@lynx-js/rspeedy'
|
|
20
|
+
* export default defineConfig({
|
|
21
|
+
* source: {
|
|
22
|
+
* alias: {
|
|
23
|
+
* xyz$: 'path/to/file.js',
|
|
24
|
+
* },
|
|
25
|
+
* },
|
|
26
|
+
* })
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* which would yield these results:
|
|
30
|
+
*
|
|
31
|
+
* ```js
|
|
32
|
+
* import Test1 from 'xyz'; // Exact match, so path/to/file.js is resolved and imported
|
|
33
|
+
* import Test2 from 'xyz/file.js'; // Not an exact match, normal resolution takes place
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
*
|
|
38
|
+
* `source.alias` is useful to control how a npm package is resolved.
|
|
39
|
+
*
|
|
40
|
+
* - Change `react` to `@lynx-js/react`:
|
|
41
|
+
*
|
|
42
|
+
* ```js
|
|
43
|
+
* import { defineConfig } from '@lynx-js/rspeedy'
|
|
44
|
+
* import { createRequire } from 'module'
|
|
45
|
+
* const require = createRequire(import.meta.url)
|
|
46
|
+
* export default defineConfig({
|
|
47
|
+
* source: {
|
|
48
|
+
* alias: {
|
|
49
|
+
* react: require.resolve('@lynx-js/react'),
|
|
50
|
+
* },
|
|
51
|
+
* },
|
|
52
|
+
* })
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* This allows you to use some third-party libraries that directly uses `react` as dependencies in ReactLynx.
|
|
56
|
+
*
|
|
57
|
+
* - Force using the same version of `dayjs`:
|
|
58
|
+
*
|
|
59
|
+
* ```js
|
|
60
|
+
* import { defineConfig } from '@lynx-js/rspeedy'
|
|
61
|
+
* import { createRequire } from 'module'
|
|
62
|
+
* const require = createRequire(import.meta.url)
|
|
63
|
+
* export default defineConfig({
|
|
64
|
+
* source: {
|
|
65
|
+
* alias: {
|
|
66
|
+
* dayjs: require.resolve('dayjs'),
|
|
67
|
+
* },
|
|
68
|
+
* },
|
|
69
|
+
* })
|
|
70
|
+
* ```
|
|
71
|
+
*
|
|
72
|
+
* Please note that this is dangerous, since all the `dayjs`(including the dependencies of a dependencies) is resolved to the version in the project.
|
|
73
|
+
* It may cause both compile-time and runtime errors due to version mismatch.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* Setting `source.alias` to `false` will ignore a module.
|
|
77
|
+
*
|
|
78
|
+
* ```js
|
|
79
|
+
* import { defineConfig } from '@lynx-js/rspeedy'
|
|
80
|
+
* export default defineConfig({
|
|
81
|
+
* source: {
|
|
82
|
+
* alias: {
|
|
83
|
+
* 'ignored-module': false,
|
|
84
|
+
* './ignored-module': false,
|
|
85
|
+
* },
|
|
86
|
+
* },
|
|
87
|
+
* })
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
alias?: Record<string, string | false | string[]> | undefined;
|
|
91
|
+
/**
|
|
92
|
+
* Include additional files that should be treated as static assets. Defaults to be `undefined`.
|
|
93
|
+
*
|
|
94
|
+
* @remarks
|
|
95
|
+
*
|
|
96
|
+
* By default, Rsbuild treats common image, font, audio, and video files as static assets.
|
|
97
|
+
* Through the source.assetsInclude config, you can specify additional file types that should be treated as static assets.
|
|
98
|
+
* These added static assets are processed using the same rules as the built-in supported static assets。
|
|
99
|
+
*
|
|
100
|
+
* The usage of `source.assetsInclude` is consistent with {@link https://rspack.dev/config/module#condition | Condition}
|
|
101
|
+
* in Rspack, which supports passing in strings, regular expressions, arrays of conditions, or logical conditions
|
|
102
|
+
* to match the module path or assets.
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
*
|
|
106
|
+
* ```js
|
|
107
|
+
* import { defineConfig } from '@lynx-js/rspeedy'
|
|
108
|
+
* export default defineConfig({
|
|
109
|
+
* source: {
|
|
110
|
+
* assetsInclude: /\.json5$/,
|
|
111
|
+
* },
|
|
112
|
+
* })
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
assetsInclude?: Rspack.RuleSetCondition | undefined;
|
|
116
|
+
/**
|
|
117
|
+
* Used to configure the decorators syntax.
|
|
118
|
+
*
|
|
119
|
+
* @remarks
|
|
120
|
+
*
|
|
121
|
+
* See {@link Decorators.version} for more information.
|
|
122
|
+
*/
|
|
123
|
+
decorators?: Decorators | undefined;
|
|
124
|
+
/**
|
|
125
|
+
* The `define` options is used to define some values or expressions at compile time.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
*
|
|
129
|
+
* Using `define` for environment variables.
|
|
130
|
+
*
|
|
131
|
+
* ```js
|
|
132
|
+
* import { defineConfig } from '@lynx-js/rspeedy'
|
|
133
|
+
* export default defineConfig({
|
|
134
|
+
* source: {
|
|
135
|
+
* define: {
|
|
136
|
+
* BUILD_VERSION: JSON.stringify(process.env.BUILD_VERSION ?? 'unknown_version'),
|
|
137
|
+
* 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
|
|
138
|
+
* },
|
|
139
|
+
* },
|
|
140
|
+
* })
|
|
141
|
+
* ```
|
|
142
|
+
*
|
|
143
|
+
* Expressions will be replaced with the corresponding code fragments:
|
|
144
|
+
*
|
|
145
|
+
* ```js
|
|
146
|
+
* const version = BUILD_VERSION;
|
|
147
|
+
* if (process.env.NODE_ENV === 'development') {}
|
|
148
|
+
*
|
|
149
|
+
* // ⬇️ Turn into being...
|
|
150
|
+
* const version = "unknown_version";
|
|
151
|
+
* if ("development" === 'development') {}
|
|
152
|
+
* ```
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
*
|
|
156
|
+
* Using `define` for `typeof`.
|
|
157
|
+
*
|
|
158
|
+
* ```js
|
|
159
|
+
* import { defineConfig } from '@lynx-js/rspeedy'
|
|
160
|
+
* export default defineConfig({
|
|
161
|
+
* source: {
|
|
162
|
+
* define: {
|
|
163
|
+
* 'typeof window': JSON.stringify("undefined"),
|
|
164
|
+
* },
|
|
165
|
+
* },
|
|
166
|
+
* })
|
|
167
|
+
* ```
|
|
168
|
+
*
|
|
169
|
+
* The `typeof` expressions will be replaced with the corresponding code fragments:
|
|
170
|
+
*
|
|
171
|
+
* ```js
|
|
172
|
+
* if (typeof window !== 'undefined') {}
|
|
173
|
+
*
|
|
174
|
+
* // ⬇️ Turn into being...
|
|
175
|
+
* if ("undefined" !== 'undefined') {}
|
|
176
|
+
* ```
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
*
|
|
180
|
+
* Using `define` with objects.
|
|
181
|
+
*
|
|
182
|
+
* ```js
|
|
183
|
+
* import { defineConfig } from '@lynx-js/rspeedy'
|
|
184
|
+
* export default defineConfig({
|
|
185
|
+
* source: {
|
|
186
|
+
* define: {
|
|
187
|
+
* 'import.meta': {
|
|
188
|
+
* foo: JSON.stringify('foo'),
|
|
189
|
+
* bar: { baz: 0 },
|
|
190
|
+
* },
|
|
191
|
+
* },
|
|
192
|
+
* },
|
|
193
|
+
* })
|
|
194
|
+
* ```
|
|
195
|
+
*
|
|
196
|
+
* Expressions will be replaced with the corresponding code fragments:
|
|
197
|
+
*
|
|
198
|
+
* ```js
|
|
199
|
+
* console.log(import.meta)
|
|
200
|
+
*
|
|
201
|
+
* // ⬇️ Turn into being...
|
|
202
|
+
* console.log({ foo: "foo", bar: { baz: 0 } })
|
|
203
|
+
* ```
|
|
204
|
+
*
|
|
205
|
+
* @remarks
|
|
206
|
+
*
|
|
207
|
+
* - If the value provided is a string, it will be utilized as a code fragment.
|
|
208
|
+
*
|
|
209
|
+
* - If the value provided is an object, all its keys will be defined in the same manner.
|
|
210
|
+
*
|
|
211
|
+
* - If the value isn't a string, it will be stringified, with functions included.
|
|
212
|
+
*
|
|
213
|
+
* - Notably, if a `typeof` prefix is attached to the key, it will be exclusively defined for `typeof` calls."
|
|
214
|
+
*/
|
|
215
|
+
define?: Record<string, string | number | boolean | undefined | Record<string, unknown>> | undefined;
|
|
216
|
+
/**
|
|
217
|
+
* The {@link Entry} option is used to set the entry module.
|
|
218
|
+
*
|
|
219
|
+
* @remarks
|
|
220
|
+
*
|
|
221
|
+
* If no value is provided, the default value `'./src/index.js'` will be used.
|
|
222
|
+
*
|
|
223
|
+
* @defaultValue `'./src/index.js'`
|
|
224
|
+
*
|
|
225
|
+
* @example
|
|
226
|
+
*
|
|
227
|
+
* - Use a single entry:
|
|
228
|
+
*
|
|
229
|
+
* ```js
|
|
230
|
+
* import { defineConfig } from '@lynx-js/rspeedy'
|
|
231
|
+
* export default defineConfig({
|
|
232
|
+
* entry: './src/pages/main/index.js',
|
|
233
|
+
* })
|
|
234
|
+
* ```
|
|
235
|
+
*
|
|
236
|
+
* @example
|
|
237
|
+
*
|
|
238
|
+
* - Use a single entry with multiple entry modules:
|
|
239
|
+
*
|
|
240
|
+
* ```js
|
|
241
|
+
* import { defineConfig } from '@lynx-js/rspeedy'
|
|
242
|
+
* export default defineConfig({
|
|
243
|
+
* entry: ['./src/prefetch.js', './src/pages/main/index.js'],
|
|
244
|
+
* })
|
|
245
|
+
* ```
|
|
246
|
+
*
|
|
247
|
+
* @example
|
|
248
|
+
*
|
|
249
|
+
* - Use multiple entries(with multiple entry modules):
|
|
250
|
+
*
|
|
251
|
+
* ```js
|
|
252
|
+
* import { defineConfig } from '@lynx-js/rspeedy'
|
|
253
|
+
* export default defineConfig({
|
|
254
|
+
* entry: {
|
|
255
|
+
* foo: './src/pages/foo/index.js',
|
|
256
|
+
* bar: ['./src/pages/bar/index.js', './src/post.js'], // multiple entry modules is allowed
|
|
257
|
+
* },
|
|
258
|
+
* })
|
|
259
|
+
* ```
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
262
|
+
*
|
|
263
|
+
* - Use multiple entries with {@link EntryDescription}:
|
|
264
|
+
*
|
|
265
|
+
* ```js
|
|
266
|
+
* import { defineConfig } from '@lynx-js/rspeedy'
|
|
267
|
+
* export default defineConfig({
|
|
268
|
+
* entry: {
|
|
269
|
+
* foo: './src/pages/foo/index.js',
|
|
270
|
+
* bar: {
|
|
271
|
+
* import: ['./src/prefetch.js', './src/pages/bar'],
|
|
272
|
+
* },
|
|
273
|
+
* },
|
|
274
|
+
* })
|
|
275
|
+
* ```
|
|
276
|
+
*/
|
|
277
|
+
entry?: Entry | undefined;
|
|
278
|
+
/**
|
|
279
|
+
* The `source.exclude` is used to specify JavaScript files that should be excluded from compilation.
|
|
280
|
+
*
|
|
281
|
+
* @remarks
|
|
282
|
+
*
|
|
283
|
+
* By default, Rsbuild compiles JavaScript files in the current directory and TypeScript/JSX files
|
|
284
|
+
* in all directories. Through the `source.exclude` config, you can specify files or directories
|
|
285
|
+
* that should be excluded from compilation.
|
|
286
|
+
* The usage of `source.exclude` is consistent with {@link https://rspack.dev/config/module#ruleexclude | Rule.exclude}
|
|
287
|
+
* in Rspack, which supports passing in strings or regular expressions to match module paths.
|
|
288
|
+
*
|
|
289
|
+
* @example
|
|
290
|
+
*
|
|
291
|
+
* - Exclude specific files or directories
|
|
292
|
+
*
|
|
293
|
+
* You can exclude specific files or directories from compilation to improve build performance
|
|
294
|
+
* or avoid processing certain files:
|
|
295
|
+
*
|
|
296
|
+
* ```js
|
|
297
|
+
* import { defineConfig } from '@lynx-js/rspeedy'
|
|
298
|
+
*
|
|
299
|
+
* export default defineConfig({
|
|
300
|
+
* source: {
|
|
301
|
+
* exclude: [
|
|
302
|
+
* // Exclude all files in the test directory
|
|
303
|
+
* /[\\/]test[\\/]/,
|
|
304
|
+
* // Exclude specific file
|
|
305
|
+
* './src/legacy-file.js',
|
|
306
|
+
* // Exclude files matching a pattern
|
|
307
|
+
* /\.stories\.(js|ts)x?$/,
|
|
308
|
+
* ],
|
|
309
|
+
* },
|
|
310
|
+
* })
|
|
311
|
+
* ```
|
|
312
|
+
*
|
|
313
|
+
* @example
|
|
314
|
+
*
|
|
315
|
+
* - Exclude third-party dependencies
|
|
316
|
+
*
|
|
317
|
+
* You can exclude specific third-party dependencies that don't need compilation:
|
|
318
|
+
*
|
|
319
|
+
* ```js
|
|
320
|
+
* import { defineConfig } from '@lynx-js/rspeedy'
|
|
321
|
+
* import path from 'node:path'
|
|
322
|
+
* import { createRequire } from 'node:module'
|
|
323
|
+
*
|
|
324
|
+
* const require = createRequire(import.meta.url)
|
|
325
|
+
*
|
|
326
|
+
* export default defineConfig({
|
|
327
|
+
* source: {
|
|
328
|
+
* exclude: [
|
|
329
|
+
* // Exclude specific package
|
|
330
|
+
* path.dirname(require.resolve('lodash')),
|
|
331
|
+
* // Exclude using regex pattern
|
|
332
|
+
* /node_modules[\\/]lodash-es[\\/]/,
|
|
333
|
+
* ],
|
|
334
|
+
* },
|
|
335
|
+
* })
|
|
336
|
+
* ```
|
|
337
|
+
*/
|
|
338
|
+
exclude?: Rspack.RuleSetCondition[] | undefined;
|
|
339
|
+
/**
|
|
340
|
+
* The `source.include` is used to specify additional JavaScript files that need to be compiled.
|
|
341
|
+
*
|
|
342
|
+
* @remarks
|
|
343
|
+
*
|
|
344
|
+
* To avoid redundant compilation, by default, Rsbuild only compiles JavaScript
|
|
345
|
+
* files in the current directory and TypeScript and JSX files in all directories.
|
|
346
|
+
* It does not compile JavaScript files under `node_modules`.
|
|
347
|
+
*
|
|
348
|
+
* Through the `source.include` config, you can specify directories or modules
|
|
349
|
+
* that need to be compiled by Rsbuild.
|
|
350
|
+
* The usage of `source.include` is consistent with {@link https://rspack.dev/config/module#ruleinclude | Rule.include}
|
|
351
|
+
* in Rspack, which supports passing in strings or regular expressions to match the module path.
|
|
352
|
+
*
|
|
353
|
+
* @example
|
|
354
|
+
*
|
|
355
|
+
* - Compile Npm Packages
|
|
356
|
+
*
|
|
357
|
+
* A typical usage scenario is to compile npm packages under `node_modules`,
|
|
358
|
+
* because some third-party dependencies have ESNext syntax, which may not be supported in Lynx.
|
|
359
|
+
* You can solve the problem by using this config to specify the dependencies
|
|
360
|
+
* that need to be compiled.
|
|
361
|
+
*
|
|
362
|
+
* ```js
|
|
363
|
+
* import { createRequire } from 'node:module'
|
|
364
|
+
* import path from 'node:path'
|
|
365
|
+
*
|
|
366
|
+
* import { defineConfig } from '@lynx-js/rspeedy'
|
|
367
|
+
*
|
|
368
|
+
* const require = createRequire(import.meta.url)
|
|
369
|
+
*
|
|
370
|
+
* export default defineConfig({
|
|
371
|
+
* source: {
|
|
372
|
+
* include: [
|
|
373
|
+
* // Method 1:
|
|
374
|
+
* // First get the path of the module by `require.resolve`
|
|
375
|
+
* // Then pass path.dirname to point to the corresponding directory
|
|
376
|
+
* path.dirname(require.resolve('query-string')),
|
|
377
|
+
* // Method 2:
|
|
378
|
+
* // Match by regular expression
|
|
379
|
+
* // All paths containing `node_modules/query-string/` will be matched
|
|
380
|
+
* /node_modules[\\/]query-string[\\/]/,
|
|
381
|
+
* ],
|
|
382
|
+
* },
|
|
383
|
+
* })
|
|
384
|
+
* ```
|
|
385
|
+
*
|
|
386
|
+
* @example
|
|
387
|
+
*
|
|
388
|
+
* - Compile Libraries in Monorepo
|
|
389
|
+
*
|
|
390
|
+
* ```js
|
|
391
|
+
* import path from 'node:path'
|
|
392
|
+
* import { fileURLToPath } from 'node:url'
|
|
393
|
+
*
|
|
394
|
+
* import { defineConfig } from '@lynx-js/rspeedy'
|
|
395
|
+
*
|
|
396
|
+
* const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
397
|
+
*
|
|
398
|
+
* const packagesDir = path.resolve(__dirname, '../../packages')
|
|
399
|
+
*
|
|
400
|
+
* export default defineConfig({
|
|
401
|
+
* source: {
|
|
402
|
+
* include: [
|
|
403
|
+
* // Compile all files in Monorepo's package directory
|
|
404
|
+
* // It is recommended to exclude the node_modules
|
|
405
|
+
* {
|
|
406
|
+
* and: [packagesDir, { not: /[\\/]node_modules[\\/]/ }],
|
|
407
|
+
* },
|
|
408
|
+
* ],
|
|
409
|
+
* },
|
|
410
|
+
* })
|
|
411
|
+
* ```
|
|
412
|
+
*/
|
|
413
|
+
include?: Rspack.RuleSetCondition[] | undefined;
|
|
414
|
+
/**
|
|
415
|
+
* The {@link TransformImport} option transforms the import paths to enable modular imports from subpaths of third-party packages, similar to the functionality provided by {@link https://npmjs.com/package/babel-plugin-import | babel-plugin-import}.
|
|
416
|
+
*
|
|
417
|
+
* @example
|
|
418
|
+
*
|
|
419
|
+
* When using the TUX component library, you can import components on demand with the following config:
|
|
420
|
+
*
|
|
421
|
+
* ```js
|
|
422
|
+
* import { defineConfig } from '@lynx-js/rspeedy'
|
|
423
|
+
*
|
|
424
|
+
* export default defineConfig({
|
|
425
|
+
* source: {
|
|
426
|
+
* transformImport: [
|
|
427
|
+
* {
|
|
428
|
+
* libraryName: 'foo',
|
|
429
|
+
* customName: 'foo/src/components/{{ member }}/{{ member }}',
|
|
430
|
+
* },
|
|
431
|
+
* ],
|
|
432
|
+
* },
|
|
433
|
+
* })
|
|
434
|
+
* ```
|
|
435
|
+
*
|
|
436
|
+
* This will transform the following source code:
|
|
437
|
+
*
|
|
438
|
+
* ```js
|
|
439
|
+
* import { Button } from 'foo'
|
|
440
|
+
* ```
|
|
441
|
+
*
|
|
442
|
+
* to:
|
|
443
|
+
*
|
|
444
|
+
* ```js
|
|
445
|
+
* import { Button } from 'foo/src/components/Button/Button'
|
|
446
|
+
* ```
|
|
447
|
+
*/
|
|
448
|
+
transformImport?: TransformImport[] | undefined;
|
|
449
|
+
/**
|
|
450
|
+
* Configure a custom `tsconfig.json` file path to use, can be a relative or absolute path. Defaults to be `./tsconfig.json`.
|
|
451
|
+
*
|
|
452
|
+
* @remarks
|
|
453
|
+
*
|
|
454
|
+
* The `tsconfigPath` configuration affects the following behaviors:
|
|
455
|
+
*
|
|
456
|
+
* - The `paths` field is used to configure {@link Source.alias | Path Aliases}.
|
|
457
|
+
*
|
|
458
|
+
* - Sets the scope and rules for the {@link https://rsbuild.dev/plugins/list/plugin-type-check | Type Check Plugin}.
|
|
459
|
+
*
|
|
460
|
+
* @example
|
|
461
|
+
*
|
|
462
|
+
* Relative path will be resolved relative to the project root directory.
|
|
463
|
+
*
|
|
464
|
+
* ```js
|
|
465
|
+
* import { defineConfig } from '@lynx-js/rspeedy'
|
|
466
|
+
* export default defineConfig({
|
|
467
|
+
* source: {
|
|
468
|
+
* tsconfigPath: './tsconfig.build.json',
|
|
469
|
+
* },
|
|
470
|
+
* })
|
|
471
|
+
* ```
|
|
472
|
+
*/
|
|
473
|
+
tsconfigPath?: string | undefined;
|
|
474
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* {@inheritdoc Source.transformImport}
|
|
3
|
+
*
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export interface TransformImport {
|
|
7
|
+
/**
|
|
8
|
+
* Whether to convert camelCase imports to kebab-case.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
*
|
|
12
|
+
* - Input:
|
|
13
|
+
*
|
|
14
|
+
* ```js
|
|
15
|
+
* import { ButtonGroup } from 'foo'
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* - Output:
|
|
19
|
+
*
|
|
20
|
+
* When set to `true`:
|
|
21
|
+
* ```js
|
|
22
|
+
* import ButtonGroup from 'foo/button-group'
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* When set to `false` or `undefined`:
|
|
26
|
+
* ```js
|
|
27
|
+
* import ButtonGroup from 'foo/ButtonGroup'
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
camelToDashComponentName?: boolean | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Customize the transformed path.
|
|
33
|
+
*
|
|
34
|
+
* @remarks
|
|
35
|
+
*
|
|
36
|
+
* You you can specify the format of the transformed path.
|
|
37
|
+
* For example, by setting it to `my-lib/{{ camelCase member }}`, you can convert the member into camelCase.
|
|
38
|
+
*
|
|
39
|
+
* The following formats are supported:
|
|
40
|
+
*
|
|
41
|
+
* - `kebabCase`: lowercase letters, words joined by hyphens. For example: `my-variable-name`.
|
|
42
|
+
*
|
|
43
|
+
* - `snakeCase`: lowercase letters, words joined by underscores. For example: `my_variable_name`.
|
|
44
|
+
*
|
|
45
|
+
* - `camelCase`: first letter lowercase, the first letter of each following word uppercase. For example: `myVariableName`.
|
|
46
|
+
*
|
|
47
|
+
* - `upperCase`: uppercase letters, other characters unchanged. For example: `MY-VARIABLE-NAME`.
|
|
48
|
+
*
|
|
49
|
+
* - `lowerCase`: lowercase letters, other characters unchanged. For example: `my-variable-name`.
|
|
50
|
+
*/
|
|
51
|
+
customName?: string | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* The original import path that needs to be transformed.
|
|
54
|
+
*
|
|
55
|
+
* @remarks
|
|
56
|
+
*
|
|
57
|
+
* This option is required.
|
|
58
|
+
*/
|
|
59
|
+
libraryName: string;
|
|
60
|
+
/**
|
|
61
|
+
* Used to splice the transformed path, the splicing rule is `${libraryName}/${libraryDirectory}/${member}`, where member is the imported member.
|
|
62
|
+
*
|
|
63
|
+
* @remarks
|
|
64
|
+
*
|
|
65
|
+
* The default value is `'lib'`.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
*
|
|
69
|
+
* - Input:
|
|
70
|
+
*
|
|
71
|
+
* ```js
|
|
72
|
+
* import { Button } from 'foo'
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* - Output:
|
|
76
|
+
*
|
|
77
|
+
* ```js
|
|
78
|
+
* import Button from 'foo/lib/button'
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
libraryDirectory?: string | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* Whether to convert import statements to default imports.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
*
|
|
87
|
+
* - Input:
|
|
88
|
+
*
|
|
89
|
+
* ```js
|
|
90
|
+
* import { Button } from 'foo'
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
93
|
+
* - Output:
|
|
94
|
+
*
|
|
95
|
+
* When set to `true`:
|
|
96
|
+
* ```js
|
|
97
|
+
* import Button from 'foo/button'
|
|
98
|
+
* ```
|
|
99
|
+
*
|
|
100
|
+
* When set to `false` or `undefined`:
|
|
101
|
+
* ```js
|
|
102
|
+
* import { Button } from 'foo/button'
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
transformToDefaultImport?: boolean | undefined;
|
|
106
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* {@inheritdoc Tools.cssExtract}
|
|
3
|
+
*
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export interface CssExtract {
|
|
7
|
+
/**
|
|
8
|
+
* {@inheritdoc @lynx-js/css-extract-webpack-plugin#LoaderOptions}
|
|
9
|
+
*/
|
|
10
|
+
loaderOptions?: CssExtractRspackLoaderOptions | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* {@inheritdoc @lynx-js/css-extract-webpack-plugin#CssExtractRspackPluginOptions}
|
|
13
|
+
*/
|
|
14
|
+
pluginOptions?: CssExtractRspackPluginOptions | undefined;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* {@inheritdoc @lynx-js/css-extract-webpack-plugin#LoaderOptions}
|
|
18
|
+
*
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
export interface CssExtractRspackLoaderOptions {
|
|
22
|
+
/**
|
|
23
|
+
* The same as {@link https://github.com/webpack-contrib/mini-css-extract-plugin#esModule}.
|
|
24
|
+
* By default, `@lynx-js/css-extract-webpack-plugin` generates JS modules that use the ES modules syntax.
|
|
25
|
+
* There are some cases in which using ES modules is beneficial,
|
|
26
|
+
* like in the case of module concatenation and tree shaking.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* You can enable a CommonJS syntax using:
|
|
30
|
+
*
|
|
31
|
+
* ```js
|
|
32
|
+
* import {CssExtractWebpackPlugin} from "@lynx-js/css-extract-webpack-plugin";
|
|
33
|
+
* export default {
|
|
34
|
+
* plugins: [new CssExtractWebpackPlugin()],
|
|
35
|
+
* module: {
|
|
36
|
+
* rules: [
|
|
37
|
+
* {
|
|
38
|
+
* test: /\.css$/i,
|
|
39
|
+
* use: [
|
|
40
|
+
* {
|
|
41
|
+
* loader: CssExtractWebpackPlugin.loader,
|
|
42
|
+
* options: {
|
|
43
|
+
* esModule: false,
|
|
44
|
+
* },
|
|
45
|
+
* },
|
|
46
|
+
* "css-loader",
|
|
47
|
+
* ],
|
|
48
|
+
* },
|
|
49
|
+
* ],
|
|
50
|
+
* },
|
|
51
|
+
* };
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* @public
|
|
55
|
+
*/
|
|
56
|
+
esModule?: boolean | undefined;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* {@inheritdoc @lynx-js/css-extract-webpack-plugin#CssExtractRspackPluginOptions}
|
|
60
|
+
*
|
|
61
|
+
* @public
|
|
62
|
+
*/
|
|
63
|
+
export interface CssExtractRspackPluginOptions {
|
|
64
|
+
/**
|
|
65
|
+
* {@inheritdoc @lynx-js/css-extract-webpack-plugin#CssExtractRspackPluginOptions.ignoreOrder}
|
|
66
|
+
*/
|
|
67
|
+
ignoreOrder?: boolean | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* {@inheritdoc @lynx-js/css-extract-webpack-plugin#CssExtractRspackPluginOptions.pathinfo}
|
|
70
|
+
*/
|
|
71
|
+
pathinfo?: boolean | undefined;
|
|
72
|
+
}
|