@rsbuild/core 1.0.1-beta.3 → 1.0.1-beta.4

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.
@@ -26,7 +26,7 @@ module.exports = __toCommonJS(transformLoader_exports);
26
26
  async function transform(source, map) {
27
27
  const callback = this.async();
28
28
  const bypass = () => callback(null, source, map);
29
- const transformId = this.getOptions().id;
29
+ const { id: transformId, getEnvironment } = this.getOptions();
30
30
  if (!transformId) {
31
31
  return bypass();
32
32
  }
@@ -39,6 +39,7 @@ async function transform(source, map) {
39
39
  resource: this.resource,
40
40
  resourcePath: this.resourcePath,
41
41
  resourceQuery: this.resourceQuery,
42
+ environment: getEnvironment(),
42
43
  addDependency: this.addDependency,
43
44
  emitFile: this.emitFile
44
45
  });
@@ -29,7 +29,7 @@ module.exports = __toCommonJS(transformRawLoader_exports);
29
29
  async function transform(source, map) {
30
30
  const callback = this.async();
31
31
  const bypass = () => callback(null, source, map);
32
- const transformId = this.getOptions().id;
32
+ const { id: transformId, getEnvironment } = this.getOptions();
33
33
  if (!transformId) {
34
34
  return bypass();
35
35
  }
@@ -42,6 +42,7 @@ async function transform(source, map) {
42
42
  resource: this.resource,
43
43
  resourcePath: this.resourcePath,
44
44
  resourceQuery: this.resourceQuery,
45
+ environment: getEnvironment(),
45
46
  addDependency: this.addDependency,
46
47
  emitFile: this.emitFile
47
48
  });
@@ -117,8 +117,6 @@ export declare const CHAIN_ID: {
117
117
  readonly MANIFEST: "webpack-manifest";
118
118
  /** ForkTsCheckerWebpackPlugin */
119
119
  readonly TS_CHECKER: "ts-checker";
120
- /** InlineChunkHtmlPlugin */
121
- readonly INLINE_HTML: "inline-html";
122
120
  /** WebpackBundleAnalyzer */
123
121
  readonly BUNDLE_ANALYZER: "bundle-analyze";
124
122
  /** ModuleFederationPlugin */
@@ -1,5 +1,7 @@
1
1
  import type { LoaderContext } from '@rspack/core';
2
- import type { RspackSourceMap } from '../types';
3
- export default function transform(this: LoaderContext<{
2
+ import type { EnvironmentContext, RspackSourceMap } from '../types';
3
+ export type TransformLoaderOptions = {
4
4
  id: string;
5
- }>, source: string, map?: string | RspackSourceMap): Promise<void>;
5
+ getEnvironment: () => EnvironmentContext;
6
+ };
7
+ export default function transform(this: LoaderContext<TransformLoaderOptions>, source: string, map?: string | RspackSourceMap): Promise<void>;
@@ -0,0 +1,2 @@
1
+ import type { RsbuildPlugin } from '../types';
2
+ export declare const pluginAppIcon: () => RsbuildPlugin;
@@ -56,6 +56,10 @@ export type ModifyHTMLTagsContext = {
56
56
  * The Compilation object of Rspack.
57
57
  */
58
58
  compilation: Rspack.Compilation;
59
+ /**
60
+ * The Compiler object of Rspack.
61
+ */
62
+ compiler: Rspack.Compiler;
59
63
  /**
60
64
  * URL prefix of assets.
61
65
  * @example 'https://example.com/'
@@ -66,7 +70,9 @@ export type ModifyHTMLTagsContext = {
66
70
  * @example 'index.html'
67
71
  */
68
72
  filename: string;
69
- /** The related environment context. */
73
+ /**
74
+ * The environment context for current build.
75
+ */
70
76
  environment: EnvironmentContext;
71
77
  };
72
78
  export type ModifyHTMLTagsFn = (tags: HTMLTags, context: ModifyHTMLTagsContext) => MaybePromise<HTMLTags>;
@@ -1,11 +1,11 @@
1
- import type { RuleSetCondition } from '@rspack/core';
2
1
  import type RspackChain from '../../compiled/rspack-chain';
3
2
  import type { RuleSetRule, Configuration as WebpackConfig, WebpackPluginInstance } from 'webpack';
4
3
  import type { ChainIdentifier } from '../configChain';
5
4
  import type { ModifyRspackConfigUtils, NormalizedConfig, NormalizedEnvironmentConfig, RsbuildConfig } from './config';
6
5
  import type { RsbuildContext } from './context';
7
- import type { ModifyBundlerChainFn, ModifyChainUtils, ModifyEnvironmentConfigFn, ModifyHTMLTagsFn, ModifyRsbuildConfigFn, OnAfterBuildFn, OnAfterCreateCompilerFn, OnAfterStartDevServerFn, OnAfterStartProdServerFn, OnBeforeBuildFn, OnBeforeCreateCompilerFn, OnBeforeStartDevServerFn, OnBeforeStartProdServerFn, OnCloseDevServerFn, OnDevCompileDoneFn, OnExitFn } from './hooks';
6
+ import type { EnvironmentContext, ModifyBundlerChainFn, ModifyChainUtils, ModifyEnvironmentConfigFn, ModifyHTMLTagsFn, ModifyRsbuildConfigFn, OnAfterBuildFn, OnAfterCreateCompilerFn, OnAfterStartDevServerFn, OnAfterStartProdServerFn, OnBeforeBuildFn, OnBeforeCreateCompilerFn, OnBeforeStartDevServerFn, OnBeforeStartProdServerFn, OnCloseDevServerFn, OnDevCompileDoneFn, OnExitFn } from './hooks';
8
7
  import type { RsbuildTarget } from './rsbuild';
8
+ import type { Rspack } from './rspack';
9
9
  import type { RspackConfig, RspackSourceMap } from './rspack';
10
10
  import type { HtmlRspackPlugin } from './thirdParty';
11
11
  import type { Falsy } from './utils';
@@ -112,6 +112,10 @@ export type TransformContext = {
112
112
  * @example '?foo=123'
113
113
  */
114
114
  resourceQuery: string;
115
+ /**
116
+ * The environment context for current build.
117
+ */
118
+ environment: EnvironmentContext;
115
119
  /**
116
120
  * Add an additional file as the dependency.
117
121
  * The file will be watched and changes to the file will trigger rebuild.
@@ -133,12 +137,12 @@ export type TransformDescriptor = {
133
137
  * Include modules that match the test assertion, the same as `rule.test`
134
138
  * @see https://rspack.dev/config/module#ruletest
135
139
  */
136
- test?: RuleSetCondition;
140
+ test?: Rspack.RuleSetCondition;
137
141
  /**
138
142
  * A condition that matches the resource query.
139
143
  * @see https://rspack.dev/config/module#ruleresourcequery
140
144
  */
141
- resourceQuery?: RuleSetCondition;
145
+ resourceQuery?: Rspack.RuleSetCondition;
142
146
  /**
143
147
  * Match based on the Rsbuild targets and only apply the transform to certain targets.
144
148
  * @see https://rsbuild.dev/config/output/targets
@@ -151,11 +155,33 @@ export type TransformDescriptor = {
151
155
  environments?: string[];
152
156
  /**
153
157
  * If raw is `true`, the transform handler will receive the Buffer type code instead of the string type.
154
- * @see https://rspack.dev/api/loader-api#raw-loader
158
+ * @see https://rspack.dev/api/loader-api/examples#raw-loader
155
159
  */
156
160
  raw?: boolean;
157
161
  };
158
162
  export type TransformFn = (descriptor: TransformDescriptor, handler: TransformHandler) => void;
163
+ export type ProcessAssetsStage = 'additional' | 'pre-process' | 'derived' | 'additions' | 'none' | 'optimize' | 'optimize-count' | 'optimize-compatibility' | 'optimize-size' | 'dev-tooling' | 'optimize-inline' | 'summarize' | 'optimize-hash' | 'optimize-transfer' | 'analyse' | 'report';
164
+ export type ProcessAssetsDescriptor = {
165
+ /**
166
+ * Specifies the order in which your asset processing logic should run relative to other plugins.
167
+ */
168
+ stage: ProcessAssetsStage;
169
+ /**
170
+ * Match based on the Rsbuild targets and only process the assets of certain targets.
171
+ * @see https://rsbuild.dev/config/output/targets
172
+ */
173
+ targets?: RsbuildTarget[];
174
+ };
175
+ export type ProcessAssetsHandler = (context: {
176
+ assets: Record<string, Rspack.sources.Source>;
177
+ compiler: Rspack.Compiler;
178
+ compilation: Rspack.Compilation;
179
+ /**
180
+ * The environment context for current build.
181
+ */
182
+ environment: EnvironmentContext;
183
+ }) => Promise<void> | void;
184
+ export type ProcessAssetsFn = (descriptor: ProcessAssetsDescriptor, handler: ProcessAssetsHandler) => void;
159
185
  declare function getNormalizedConfig(): NormalizedConfig;
160
186
  declare function getNormalizedConfig(options: {
161
187
  environment: string;
@@ -198,5 +224,9 @@ export type RsbuildPluginAPI = Readonly<{
198
224
  * Used to transform the code of modules.
199
225
  */
200
226
  transform: TransformFn;
227
+ /**
228
+ * Process all the asset generated by Rspack.
229
+ */
230
+ processAssets: ProcessAssetsFn;
201
231
  }>;
202
232
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/core",
3
- "version": "1.0.1-beta.3",
3
+ "version": "1.0.1-beta.4",
4
4
  "description": "The Rspack-based build tool.",
5
5
  "homepage": "https://rsbuild.dev",
6
6
  "bugs": {
@@ -49,7 +49,7 @@
49
49
  "@rspack/core": "1.0.0-alpha.5",
50
50
  "@rspack/lite-tapable": "1.0.0-alpha.5",
51
51
  "@swc/helpers": "0.5.11",
52
- "caniuse-lite": "^1.0.30001642",
52
+ "caniuse-lite": "^1.0.30001643",
53
53
  "core-js": "~3.37.1",
54
54
  "postcss": "^8.4.39"
55
55
  },
@@ -1,13 +0,0 @@
1
- import type { Compiler } from '@rspack/core';
2
- type AppIconOptions = {
3
- distDir: string;
4
- iconPath: string;
5
- };
6
- export declare class HtmlAppIconPlugin {
7
- readonly name: string;
8
- readonly distDir: string;
9
- readonly iconPath: string;
10
- constructor(options: AppIconOptions);
11
- apply(compiler: Compiler): void;
12
- }
13
- export {};
@@ -1,29 +0,0 @@
1
- import type { Compiler } from '@rspack/core';
2
- import type { InlineChunkTest } from '../types';
3
- export type InlineChunkHtmlPluginOptions = {
4
- styleTests: InlineChunkTest[];
5
- scriptTests: InlineChunkTest[];
6
- distPath: {
7
- js?: string;
8
- css?: string;
9
- };
10
- };
11
- export declare class InlineChunkHtmlPlugin {
12
- name: string;
13
- styleTests: InlineChunkTest[];
14
- scriptTests: InlineChunkTest[];
15
- distPath: InlineChunkHtmlPluginOptions['distPath'];
16
- inlinedAssets: Set<string>;
17
- constructor({ styleTests, scriptTests, distPath, }: InlineChunkHtmlPluginOptions);
18
- /**
19
- * If we inlined the chunk to HTML,we should update the value of sourceMappingURL,
20
- * because the relative path of source code has been changed.
21
- * @param source
22
- */
23
- private updateSourceMappingURL;
24
- private matchTests;
25
- private getInlinedScriptTag;
26
- private getInlinedCSSTag;
27
- private getInlinedTag;
28
- apply(compiler: Compiler): void;
29
- }