@esmx/rspack 3.0.0-rc.11 → 3.0.0-rc.111

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.
Files changed (76) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +48 -20
  3. package/README.zh-CN.md +57 -0
  4. package/dist/index.d.ts +2 -4
  5. package/dist/index.mjs +4 -4
  6. package/dist/module-link/config.d.ts +5 -0
  7. package/dist/module-link/config.mjs +100 -0
  8. package/dist/module-link/config1.d.ts +3 -0
  9. package/dist/module-link/config1.mjs +16 -0
  10. package/dist/module-link/config2.d.ts +3 -0
  11. package/dist/module-link/config2.mjs +17 -0
  12. package/dist/module-link/index.d.ts +4 -0
  13. package/dist/module-link/index.mjs +8 -0
  14. package/dist/module-link/manifest-plugin.d.ts +14 -0
  15. package/dist/module-link/manifest-plugin.mjs +141 -0
  16. package/dist/module-link/parse.d.ts +2 -0
  17. package/dist/module-link/parse.mjs +24 -0
  18. package/dist/module-link/types.d.ts +25 -0
  19. package/dist/rspack/app.d.ts +183 -0
  20. package/dist/{app.mjs → rspack/app.mjs} +18 -46
  21. package/dist/rspack/build-target.d.ts +7 -0
  22. package/dist/rspack/build-target.mjs +0 -0
  23. package/dist/{config.d.ts → rspack/chain-config.d.ts} +3 -4
  24. package/dist/rspack/chain-config.mjs +113 -0
  25. package/dist/rspack/index.d.ts +3 -0
  26. package/dist/rspack/index.mjs +4 -0
  27. package/dist/rspack/loader.d.ts +9 -0
  28. package/dist/{loader.mjs → rspack/loader.mjs} +2 -22
  29. package/dist/rspack/pack.d.ts +9 -0
  30. package/dist/{pack.mjs → rspack/pack.mjs} +33 -25
  31. package/dist/rspack/pack.test.d.ts +1 -0
  32. package/dist/rspack/pack.test.mjs +180 -0
  33. package/dist/rspack/utils/rsbuild.d.ts +6 -0
  34. package/dist/{utils → rspack/utils}/rsbuild.mjs +7 -37
  35. package/dist/rspack-html/index.d.ts +168 -0
  36. package/dist/rspack-html/index.mjs +160 -0
  37. package/dist/rspack-html/target-setting.d.ts +17 -0
  38. package/dist/rspack-html/target-setting.mjs +31 -0
  39. package/dist/rspack-html/target-setting.test.d.ts +1 -0
  40. package/dist/rspack-html/target-setting.test.mjs +105 -0
  41. package/package.json +23 -21
  42. package/src/index.ts +7 -6
  43. package/src/module-link/config.ts +157 -0
  44. package/src/module-link/config1.ts +24 -0
  45. package/src/module-link/config2.ts +28 -0
  46. package/src/module-link/index.ts +19 -0
  47. package/src/module-link/manifest-plugin.ts +179 -0
  48. package/src/module-link/parse.ts +31 -0
  49. package/src/module-link/types.ts +31 -0
  50. package/src/{app.ts → rspack/app.ts} +104 -107
  51. package/src/rspack/build-target.ts +7 -0
  52. package/src/rspack/chain-config.ts +165 -0
  53. package/src/rspack/index.ts +8 -0
  54. package/src/{loader.ts → rspack/loader.ts} +3 -22
  55. package/src/rspack/pack.test.ts +215 -0
  56. package/src/rspack/pack.ts +101 -0
  57. package/src/{utils → rspack/utils}/rsbuild.ts +11 -40
  58. package/src/rspack-html/index.ts +495 -0
  59. package/src/rspack-html/target-setting.test.ts +123 -0
  60. package/src/rspack-html/target-setting.ts +52 -0
  61. package/dist/app.d.ts +0 -160
  62. package/dist/build-target.d.ts +0 -8
  63. package/dist/config.mjs +0 -142
  64. package/dist/html-app.d.ts +0 -299
  65. package/dist/html-app.mjs +0 -214
  66. package/dist/loader.d.ts +0 -30
  67. package/dist/pack.d.ts +0 -2
  68. package/dist/utils/rsbuild.d.ts +0 -12
  69. package/src/build-target.ts +0 -8
  70. package/src/config.ts +0 -171
  71. package/src/html-app.ts +0 -560
  72. package/src/pack.ts +0 -79
  73. /package/dist/{build-target.mjs → module-link/types.mjs} +0 -0
  74. /package/dist/{utils → rspack/utils}/index.d.ts +0 -0
  75. /package/dist/{utils → rspack/utils}/index.mjs +0 -0
  76. /package/src/{utils → rspack/utils}/index.ts +0 -0
package/dist/html-app.mjs DELETED
@@ -1,214 +0,0 @@
1
- import {
2
- rspack
3
- } from "@rspack/core";
4
- import NodePolyfillPlugin from "node-polyfill-webpack-plugin";
5
- import {
6
- createRspackApp
7
- } from "./app.mjs";
8
- import { RSPACK_LOADER } from "./loader.mjs";
9
- export async function createRspackHtmlApp(esmx, options) {
10
- options = {
11
- ...options,
12
- target: {
13
- web: ["chrome>=87", "edge>=88", "firefox>=78", "safari>=14"],
14
- node: ["node>=22.6"],
15
- ...options?.target
16
- },
17
- css: options?.css ? options.css : esmx.isProd ? "css" : "js"
18
- };
19
- return createRspackApp(esmx, {
20
- ...options,
21
- config(context) {
22
- const { config, buildTarget } = context;
23
- config.stats = "errors-warnings";
24
- config.module = {
25
- ...config.module,
26
- rules: [
27
- ...config.module?.rules ?? [],
28
- {
29
- test: /\.(jpe?g|png|gif|bmp|webp|svg)$/i,
30
- type: "asset/resource",
31
- generator: {
32
- filename: filename(esmx, "images")
33
- }
34
- },
35
- {
36
- test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)$/i,
37
- type: "asset/resource",
38
- generator: {
39
- filename: filename(esmx, "media")
40
- }
41
- },
42
- {
43
- test: /\.(woff|woff2|eot|ttf|otf)(\?.*)?$/i,
44
- type: "asset/resource",
45
- generator: {
46
- filename: filename(esmx, "fonts")
47
- }
48
- },
49
- {
50
- test: /\.json$/i,
51
- type: "json"
52
- },
53
- {
54
- test: /\.worker\.(c|m)?(t|j)s$/i,
55
- loader: options.loaders?.workerRspackLoader ?? RSPACK_LOADER.workerRspackLoader,
56
- options: {
57
- esModule: false,
58
- filename: `${esmx.name}/workers/[name].[contenthash]${esmx.isProd ? ".final" : ""}.js`
59
- }
60
- },
61
- {
62
- test: /\.(ts|mts)$/i,
63
- loader: options.loaders?.builtinSwcLoader ?? RSPACK_LOADER.builtinSwcLoader,
64
- options: {
65
- env: {
66
- targets: buildTarget === "client" ? options?.target?.web : options?.target?.node,
67
- ...options?.swcLoader?.env
68
- },
69
- jsc: {
70
- parser: {
71
- syntax: "typescript",
72
- ...options?.swcLoader?.jsc?.parser
73
- },
74
- ...options?.swcLoader?.jsc
75
- },
76
- ...options?.swcLoader
77
- },
78
- type: "javascript/auto"
79
- }
80
- ]
81
- };
82
- config.optimization = {
83
- ...config.optimization,
84
- minimizer: [
85
- new rspack.SwcJsMinimizerRspackPlugin({
86
- minimizerOptions: {
87
- format: {
88
- comments: false
89
- }
90
- }
91
- }),
92
- new rspack.LightningCssMinimizerRspackPlugin({
93
- minimizerOptions: {
94
- targets: options.target?.web,
95
- errorRecovery: false
96
- }
97
- })
98
- ]
99
- };
100
- config.plugins = [
101
- new NodePolyfillPlugin(),
102
- ...config.plugins ?? []
103
- ];
104
- config.devtool = false;
105
- config.cache = false;
106
- if (options.definePlugin) {
107
- const defineOptions = {};
108
- Object.entries(options.definePlugin).forEach(
109
- ([name, value]) => {
110
- const targetValue = typeof value === "string" ? value : value[buildTarget];
111
- if (typeof targetValue === "string" && name !== targetValue) {
112
- defineOptions[name] = targetValue;
113
- }
114
- }
115
- );
116
- if (Object.keys(defineOptions).length) {
117
- config.plugins.push(new rspack.DefinePlugin(defineOptions));
118
- }
119
- }
120
- config.resolve = {
121
- ...config.resolve,
122
- extensions: ["...", ".ts"]
123
- };
124
- addCssConfig(esmx, options, context);
125
- options?.config?.(context);
126
- }
127
- });
128
- }
129
- function filename(esmx, name, ext = "[ext]") {
130
- return esmx.isProd ? `${name}/[name].[contenthash:8].final${ext}` : `${name}/[path][name]${ext}`;
131
- }
132
- function addCssConfig(esmx, options, { config }) {
133
- if (options.css === false) {
134
- return;
135
- }
136
- if (options.css === "js") {
137
- const cssRule = [
138
- {
139
- loader: options.loaders?.styleLoader ?? RSPACK_LOADER.styleLoader,
140
- options: options.styleLoader
141
- },
142
- {
143
- loader: options.loaders?.cssLoader ?? RSPACK_LOADER.cssLoader,
144
- options: options.cssLoader
145
- },
146
- {
147
- loader: options.loaders?.lightningcssLoader ?? RSPACK_LOADER.lightningcssLoader,
148
- options: {
149
- targets: options.target?.web ?? [],
150
- minify: esmx.isProd
151
- }
152
- }
153
- ];
154
- const lessRule = [
155
- {
156
- loader: options.loaders?.lessLoader ?? RSPACK_LOADER.lessLoader,
157
- options: options.lessLoader
158
- }
159
- ];
160
- if (options.styleResourcesLoader) {
161
- lessRule.push({
162
- loader: options.loaders?.styleResourcesLoader ?? RSPACK_LOADER.styleResourcesLoader,
163
- options: options.styleResourcesLoader
164
- });
165
- }
166
- config.module = {
167
- ...config.module,
168
- rules: [
169
- ...config.module?.rules ?? [],
170
- {
171
- test: /\.less$/,
172
- use: [...cssRule, ...lessRule],
173
- type: "javascript/auto"
174
- },
175
- {
176
- test: /\.css$/,
177
- use: cssRule,
178
- type: "javascript/auto"
179
- }
180
- ]
181
- };
182
- return;
183
- }
184
- config.experiments = {
185
- ...config.experiments,
186
- css: true
187
- };
188
- if (!config.experiments.css) {
189
- return;
190
- }
191
- const lessLoaders = [
192
- {
193
- loader: options.loaders?.lessLoader ?? RSPACK_LOADER.lessLoader,
194
- options: options.lessLoader
195
- }
196
- ];
197
- if (options.styleResourcesLoader) {
198
- lessLoaders.push({
199
- loader: options.loaders?.styleResourcesLoader ?? RSPACK_LOADER.styleResourcesLoader,
200
- options: options.styleResourcesLoader
201
- });
202
- }
203
- config.module = {
204
- ...config.module,
205
- rules: [
206
- ...config.module?.rules ?? [],
207
- {
208
- test: /\.less$/,
209
- use: [...lessLoaders],
210
- type: "css"
211
- }
212
- ]
213
- };
214
- }
package/dist/loader.d.ts DELETED
@@ -1,30 +0,0 @@
1
- export declare const RSPACK_LOADER: {
2
- /**
3
- * Rspack 内置的 builtin:swc-loader
4
- */
5
- builtinSwcLoader: string;
6
- /**
7
- * Rspack 内置的 lightningcss-loader
8
- */
9
- lightningcssLoader: string;
10
- /**
11
- * css-loader
12
- */
13
- cssLoader: string;
14
- /**
15
- * style-loader
16
- */
17
- styleLoader: string;
18
- /**
19
- * less-loader
20
- */
21
- lessLoader: string;
22
- /**
23
- * style-resources-loader
24
- */
25
- styleResourcesLoader: string;
26
- /**
27
- * worker-rspack-loader
28
- */
29
- workerRspackLoader: string;
30
- };
package/dist/pack.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import type { Esmx } from '@esmx/core';
2
- export declare function pack(esmx: Esmx): Promise<boolean>;
@@ -1,12 +0,0 @@
1
- import { type Compiler, type RspackOptions } from '@rspack/core';
2
- export declare function createRsBuild(options: RspackOptions[]): {
3
- readonly compilers: Compiler[];
4
- build(): Promise<boolean>;
5
- watch(): void;
6
- };
7
- export declare class RsBuild {
8
- private compiler;
9
- constructor(options: RspackOptions);
10
- build(): Promise<boolean>;
11
- watch(): void;
12
- }
@@ -1,8 +0,0 @@
1
- /**
2
- * 构建目标环境类型
3
- * @description 定义了应用程序的构建目标环境,用于配置构建过程中的特定优化和功能
4
- * - node: 构建为 Node.js 环境运行的代码
5
- * - client: 构建为浏览器环境运行的代码
6
- * - server: 构建为服务端环境运行的代码
7
- */
8
- export type BuildTarget = 'node' | 'client' | 'server';
package/src/config.ts DELETED
@@ -1,171 +0,0 @@
1
- import type { Esmx } from '@esmx/core';
2
- import { moduleLinkPlugin } from '@esmx/rspack-module-link-plugin';
3
- import {
4
- type ExternalItem,
5
- type Plugins,
6
- type RspackOptions,
7
- rspack
8
- } from '@rspack/core';
9
- import nodeExternals from 'webpack-node-externals';
10
- import type { RspackAppOptions } from './app';
11
- import type { BuildTarget } from './build-target';
12
-
13
- /**
14
- * 构建 Client、Server、Node 的基础配置
15
- */
16
- export function createRspackConfig(
17
- esmx: Esmx,
18
- buildTarget: BuildTarget,
19
- options: RspackAppOptions
20
- ): RspackOptions {
21
- const isWebApp = buildTarget === 'client' || buildTarget === 'server';
22
- const isHot = buildTarget === 'client' && !esmx.isProd;
23
- return {
24
- /**
25
- * 项目根目录,不可修改
26
- */
27
- context: esmx.root,
28
- entry: (() => {
29
- const importPaths: string[] = [];
30
- switch (buildTarget) {
31
- case 'client':
32
- importPaths.push(esmx.resolvePath('src/entry.client.ts'));
33
- isHot &&
34
- importPaths.push(
35
- `${resolve('webpack-hot-middleware/client')}?path=${esmx.basePath}hot-middleware&timeout=5000&overlay=false`
36
- );
37
- break;
38
- case 'server':
39
- importPaths.push(esmx.resolvePath('src/entry.server.ts'));
40
- break;
41
- case 'node':
42
- importPaths.push(esmx.resolvePath('src/entry.node.ts'));
43
- break;
44
- }
45
- return {
46
- [`./src/entry.${buildTarget}`]: {
47
- import: importPaths
48
- }
49
- };
50
- })(),
51
- output: {
52
- clean: esmx.isProd,
53
- module: true,
54
- chunkFormat: esmx.isProd ? 'module' : undefined,
55
- chunkLoading: esmx.isProd ? 'import' : undefined,
56
- chunkFilename: esmx.isProd
57
- ? 'chunks/[name].[contenthash:8].final.js'
58
- : 'chunks/[name].js',
59
- library: {
60
- type: esmx.isProd ? 'modern-module' : 'module'
61
- },
62
- filename:
63
- buildTarget !== 'node' && esmx.isProd
64
- ? '[name].[contenthash:8].final.js'
65
- : '[name].js',
66
- cssFilename: esmx.isProd
67
- ? '[name].[contenthash:8].final.css'
68
- : '[name].css',
69
- cssChunkFilename: esmx.isProd
70
- ? 'chunks/[name].[contenthash:8].final.css'
71
- : 'chunks/[name].css',
72
- publicPath:
73
- buildTarget === 'client'
74
- ? 'auto'
75
- : `${esmx.basePathPlaceholder}${esmx.basePath}`,
76
- uniqueName: esmx.varName,
77
- hotUpdateChunkFilename: '__hot__/[id].[fullhash].hot-update.js',
78
- hotUpdateMainFilename:
79
- '__hot__/[runtime].[fullhash].hot-update.json',
80
- path: ((): string => {
81
- switch (buildTarget) {
82
- case 'client':
83
- return esmx.resolvePath('dist/client');
84
- case 'server':
85
- return esmx.resolvePath('dist/server');
86
- case 'node':
87
- return esmx.resolvePath('dist/node');
88
- }
89
- })(),
90
- environment: {
91
- nodePrefixForCoreModules: true
92
- }
93
- },
94
- // 默认插件,不可修改
95
- plugins: ((): Plugins => {
96
- return [
97
- // 进度条插件
98
- new rspack.ProgressPlugin({
99
- prefix: buildTarget
100
- }),
101
- // 模块链接插件
102
- isWebApp ? moduleLinkPlugin(esmx.moduleConfig) : false,
103
- // 热更新插件
104
- isHot ? new rspack.HotModuleReplacementPlugin() : false
105
- ];
106
- })(),
107
- module: {
108
- parser: {
109
- javascript: {
110
- url: buildTarget === 'client' ? true : 'relative',
111
- importMeta: false,
112
- strictExportPresence: true
113
- }
114
- },
115
- generator: {
116
- asset: {
117
- emit: buildTarget === 'client'
118
- },
119
- 'asset/resource': {
120
- emit: buildTarget === 'client'
121
- }
122
- },
123
- rules: []
124
- },
125
- resolve: {
126
- alias: {
127
- [esmx.name]: esmx.root
128
- }
129
- },
130
- optimization: {
131
- minimize: options.minimize ?? esmx.isProd,
132
- avoidEntryIife: esmx.isProd,
133
- concatenateModules: esmx.isProd,
134
- emitOnErrors: true,
135
- splitChunks: {
136
- chunks: 'async'
137
- }
138
- },
139
- externalsPresets: {
140
- web: buildTarget === 'client',
141
- node: buildTarget === 'server' || buildTarget === 'node'
142
- },
143
- externalsType: 'module-import',
144
- externals: ((): ExternalItem[] => {
145
- if (buildTarget === 'node') {
146
- return [
147
- // @ts-ignore
148
- nodeExternals({
149
- // @ts-ignore
150
- importType: 'module-import'
151
- })
152
- ];
153
- }
154
- return [];
155
- })(),
156
- experiments: {
157
- outputModule: true,
158
- parallelCodeSplitting: true,
159
- rspackFuture: {
160
- bundlerInfo: { force: false }
161
- }
162
- },
163
- target: buildTarget === 'client' ? 'web' : 'node22.6',
164
- mode: esmx.isProd ? 'production' : 'development',
165
- cache: !esmx.isProd
166
- };
167
- }
168
-
169
- function resolve(name: string) {
170
- return new URL(import.meta.resolve(name)).pathname;
171
- }