Skip to content

Commit

Permalink
feat: improve description, types and JSDoc for entry options (#8361)
Browse files Browse the repository at this point in the history
* feat: improve description, types and JSDoc for entry options

* fix

* docs: update
  • Loading branch information
chenjiahan authored Nov 7, 2024
1 parent 3234c74 commit dfb5cf7
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 152 deletions.
161 changes: 67 additions & 94 deletions packages/rspack/etc/core.api.md

Large diffs are not rendered by default.

31 changes: 15 additions & 16 deletions packages/rspack/src/builtin-plugin/EntryPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,29 @@ import {
} from "@rspack/binding";

import {
type ChunkLoading,
type EntryRuntime,
type Filename,
type Layer,
type LibraryOptions,
type PublicPath,
type EntryDescriptionNormalized,
getRawChunkLoading,
getRawLibrary
} from "../config";
import { isNil } from "../util";
import { create } from "./base";

export type EntryOptions = {
/**
* Options for the `EntryPlugin`.
*/
export type EntryOptions = Omit<EntryDescriptionNormalized, "import"> & {
/**
* The name of the entry chunk.
*/
name?: string;
runtime?: EntryRuntime;
chunkLoading?: ChunkLoading;
asyncChunks?: boolean;
publicPath?: PublicPath;
baseUri?: string;
filename?: Filename;
library?: LibraryOptions;
layer?: Layer;
dependOn?: string[];
};

/**
* The entry plugin that will handle creation of the `EntryDependency`.
* It adds an entry chunk on compilation. The chunk is named `options.name` and
* contains only one module (plus dependencies). The module is resolved from
* `entry` in `context` (absolute path).
*/
export const EntryPlugin = create(
BuiltinPluginName.EntryPlugin,
(
Expand Down
29 changes: 14 additions & 15 deletions packages/rspack/src/config/normalization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
import type { Compilation } from "../Compilation";
import type {
AssetModuleFilename,
AsyncChunks,
Bail,
BaseUri,
CacheOptions,
ChunkFilename,
ChunkLoading,
Expand All @@ -31,8 +29,7 @@ import type {
DevtoolNamespace,
EnabledLibraryTypes,
EnabledWasmLoadingTypes,
EntryFilename,
EntryRuntime,
EntryDescription,
EntryStatic,
Environment,
Externals,
Expand All @@ -53,7 +50,6 @@ import type {
ImportMetaName,
Incremental,
InfrastructureLogging,
Layer,
LazyCompilationOptions,
LibraryOptions,
Loader,
Expand Down Expand Up @@ -459,18 +455,21 @@ export type EntryNormalized = EntryDynamicNormalized | EntryStaticNormalized;
export interface EntryStaticNormalized {
[k: string]: EntryDescriptionNormalized;
}
export interface EntryDescriptionNormalized {

export type EntryDescriptionNormalized = Pick<
EntryDescription,
| "runtime"
| "chunkLoading"
| "asyncChunks"
| "publicPath"
| "baseUri"
| "filename"
| "library"
| "layer"
> & {
import?: string[];
runtime?: EntryRuntime;
chunkLoading?: ChunkLoading;
asyncChunks?: AsyncChunks;
publicPath?: PublicPath;
baseUri?: BaseUri;
filename?: EntryFilename;
library?: LibraryOptions;
dependOn?: string[];
layer?: Layer;
}
};

export interface OutputNormalized {
path?: Path;
Expand Down
20 changes: 17 additions & 3 deletions packages/rspack/src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,14 @@ export type EntryItem = string | string[];
/** The entry that the current entry depends on. With dependOn option you can share the modules from one entry chunk to another. */
export type EntryDependOn = string | string[];

/**
* An object with entry point description.
*/
export type EntryDescription = {
/**
* The path to the entry module.
* @default './src/index.js'
* @example ['./src/index.js', './src/foo.js']
* */
import: EntryItem;

Expand Down Expand Up @@ -199,13 +203,23 @@ export type EntryDescription = {
/** The filename of the entry chunk. */
filename?: EntryFilename;

/** The format of the chunk generated by this entry as a library. */
/**
* The format of the chunk generated by this entry as a library.
* For detailed configuration, see `output.library`.
*/
library?: LibraryOptions;

/** The entry that the current entry depends on. With dependOn option you can share the modules from one entry chunk to another. */
/**
* The entry that the current entry depends on. With `dependOn` option
* you can share the modules from one entry chunk to another.
*/
dependOn?: EntryDependOn;

/** The layer of this entry, make the corresponding configuration take effect through layer matching in SplitChunks, Rules, Stats, and Externals. */
/**
* Specifies the layer in which modules of this entrypoint are placed.
* Make the corresponding configuration take effect through layer matching
* in split chunks, rules, stats, and externals.
*/
layer?: Layer;
};

Expand Down
28 changes: 25 additions & 3 deletions website/docs/en/config/entry.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,29 @@ When you set `entry` to an object, you can set the value of the entry to a descr
defaultValueList={[{ defaultValue: "'./src/index.js'" }]}
/>

The path to the entry module.
The path or paths to the entry modules.

```ts title="rspack.config.js"
module.exports = {
entry: {
foo: {
import: './src/foo.js',
},
},
};
```

Multiple paths can be set in the `import` property:

```ts title="rspack.config.js"
module.exports = {
entry: {
foo: {
import: ['./src/foo.js', './src/bar.js'],
},
},
};
```

#### EntryDescription.runtime

Expand Down Expand Up @@ -124,7 +146,7 @@ module.exports = {
defaultValueList={[{ defaultValue: 'undefined' }]}
/>

How this entry load other chunks.
How this entry load other chunks. Methods included by default are `'jsonp'` (web), `'import'` (ESM), `'import-scripts'` (WebWorker), `'require'` (sync node.js), `'async-node'` (async node.js), but others might be added by plugins.

#### EntryDescription.asyncChunks

Expand Down Expand Up @@ -200,7 +222,7 @@ The default value can be affected by different [target](/config/target):
defaultValueList={[{ defaultValue: 'undefined' }]}
/>

The layer of this entry, make the corresponding configuration take effect through layer matching in split chunks, [rules](/config/module#ruleissuerlayer), stats, and externals.
Specifies the layer in which modules of this entrypoint are placed. Make the corresponding configuration take effect through layer matching in split chunks, [rules](/config/module#ruleissuerlayer), stats, and externals.

:::warning
This configuration will only take effect when [experiments.layers](/config/experiments#experimentslayers) is `true`.
Expand Down
21 changes: 12 additions & 9 deletions website/docs/en/plugins/webpack/entry-plugin.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@ To adjust settings related to the entry module.
- **Type:**

```ts
type EntryOptions = {
name?: string;
runtime?: EntryRuntime;
chunkLoading?: ChunkLoading;
asyncChunks?: boolean;
publicPath?: PublicPath;
baseUri?: string;
filename?: Filename;
};
type EntryOptions =
| string
| (Omit<EntryDescriptionNormalized, 'import'> & {
/**
* The name of the entry chunk.
*/
name?: string;
});
```

If `options` is a string, its value will be used as `name`.

Please refer to [Entry Description Object](/config/entry#entry-description-object) for all available options.
28 changes: 25 additions & 3 deletions website/docs/zh/config/entry.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,29 @@ module.exports = {
defaultValueList={[{ defaultValue: "'./src/index.js'" }]}
/>

入口模块的路径。
一个或多个入口模块的路径。

```ts title="rspack.config.js"
module.exports = {
entry: {
foo: {
import: './src/foo.js',
},
},
};
```

`import` 属性可以设置多个路径:

```ts title="rspack.config.js"
module.exports = {
entry: {
foo: {
import: ['./src/foo.js', './src/bar.js'],
},
},
};
```

#### EntryDescription.runtime

Expand Down Expand Up @@ -124,7 +146,7 @@ module.exports = {
defaultValueList={[{ defaultValue: 'undefined' }]}
/>

设置当前入口在加载 chunk 时的加载方式。
设置当前入口在加载 chunk 时的加载方式。默认包含的方式有 `'jsonp'` (web), `'import'` (ESM), `'import-scripts'` (WebWorker), `'require'` (sync node.js), `'async-node'` (async node.js),其他方式可由插件提供。

#### EntryDescription.asyncChunks

Expand Down Expand Up @@ -200,7 +222,7 @@ module.exports = {
defaultValueList={[{ defaultValue: 'undefined' }]}
/>

设置当前入口的 Layer,以在 split chunks, [rules](/config/module#ruleissuerlayer)、stats、externals 中通过 layer 匹配使对应的配置生效。
指定当前入口的模块所在的 layer。用于在 split chunks, [rules](/config/module#ruleissuerlayer)、stats、externals 中通过 layer 匹配使对应的配置生效。

:::warning
只有在 [experiments.layers = true](/config/experiments#experimentslayers) 时该配置才会生效。
Expand Down
21 changes: 12 additions & 9 deletions website/docs/zh/plugins/webpack/entry-plugin.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@ new rspack.EntryPlugin(context, entry, options);
- **Type:**

```ts
type EntryOptions = {
name?: string;
runtime?: EntryRuntime;
chunkLoading?: ChunkLoading;
asyncChunks?: boolean;
publicPath?: PublicPath;
baseUri?: string;
filename?: Filename;
};
type EntryOptions =
| string
| (Omit<EntryDescriptionNormalized, 'import'> & {
/**
* The name of the entry chunk.
*/
name?: string;
});
```

`options` 为字符串时,它的值会被作为 `name` 使用。

请参考 [入口描述对象](/config/entry#入口描述对象) 了解所有可用的选项。

2 comments on commit dfb5cf7

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Benchmark detail: Open

Name Base (2024-11-07 52d7dcd) Current Change
10000_big_production-mode + exec 44.3 s ± 1.17 s 44.5 s ± 558 ms +0.51 %
10000_development-mode + exec 1.84 s ± 21 ms 1.83 s ± 19 ms -0.72 %
10000_development-mode_hmr + exec 659 ms ± 13 ms 644 ms ± 3 ms -2.20 %
10000_production-mode + exec 2.43 s ± 50 ms 2.43 s ± 26 ms -0.24 %
arco-pro_development-mode + exec 1.78 s ± 45 ms 1.74 s ± 52 ms -2.26 %
arco-pro_development-mode_hmr + exec 431 ms ± 1.5 ms 430 ms ± 2.5 ms -0.06 %
arco-pro_production-mode + exec 3.18 s ± 66 ms 3.2 s ± 55 ms +0.70 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 3.24 s ± 66 ms 3.26 s ± 84 ms +0.62 %
threejs_development-mode_10x + exec 1.6 s ± 13 ms 1.6 s ± 15 ms -0.21 %
threejs_development-mode_10x_hmr + exec 777 ms ± 8.3 ms 778 ms ± 12 ms +0.18 %
threejs_production-mode_10x + exec 4.98 s ± 18 ms 4.99 s ± 31 ms +0.23 %

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Ran ecosystem CI: Open

suite result
modernjs ✅ success
_selftest ✅ success
rspress ✅ success
rslib ✅ success
rsbuild ✅ success
examples ✅ success
devserver ✅ success

Please sign in to comment.