Skip to content

Commit c90ea5a

Browse files
authored
feat(builder): support output.enableAssetManifest in Rspack (#3721)
feat(builder): support output.enableAssetManifest in Rspack
1 parent e81eeaf commit c90ea5a

File tree

15 files changed

+267
-164
lines changed

15 files changed

+267
-164
lines changed

.changeset/tame-berries-exercise.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@modern-js/builder-rspack-provider': patch
3+
---
4+
5+
feat(builder): support output.enableAssetManifest in Rspack
6+
7+
8+
feat(builder): 在使用 Rspack 构建时支持 output.enableAssetManifest 配置项

packages/builder/builder-rspack-provider/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"@rspack/dev-middleware": "0.0.0-canary-22b006c-20230517164249",
6262
"@rspack/plugin-html": "0.0.0-canary-22b006c-20230517164249",
6363
"@rspack/postcss-loader": "0.0.0-canary-22b006c-20230517164249",
64+
"rspack-manifest-plugin": "5.0.0-alpha0",
6465
"caniuse-lite": "^1.0.30001451",
6566
"core-js": "~3.30.0",
6667
"rspack-plugin-virtual-module": "0.1.0"
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import type { BuilderPlugin } from '../types';
2+
import { generateManifest } from '@modern-js/builder-shared';
3+
4+
export const builderPluginManifest = (): BuilderPlugin => ({
5+
name: 'builder-plugin-manifest',
6+
7+
setup(api) {
8+
api.modifyBundlerChain(async (chain, { CHAIN_ID }) => {
9+
const config = api.getNormalizedConfig();
10+
11+
if (!config.output.enableAssetManifest) {
12+
return;
13+
}
14+
15+
const { WebpackManifestPlugin } = await import('rspack-manifest-plugin');
16+
const publicPath = chain.output.get('publicPath');
17+
18+
chain.plugin(CHAIN_ID.PLUGIN.MANIFEST).use(WebpackManifestPlugin, [
19+
{
20+
fileName: 'asset-manifest.json',
21+
publicPath,
22+
generate: generateManifest,
23+
},
24+
]);
25+
});
26+
},
27+
});

packages/builder/builder-rspack-provider/src/shared/plugin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export const applyDefaultPlugins = (plugins: Plugins) =>
2828
import('../plugins/less').then(m => m.builderPluginLess()),
2929
import('../plugins/sass').then(m => m.builderPluginSass()),
3030
import('../plugins/minimize').then(m => m.builderPluginMinimize()),
31+
import('../plugins/manifest').then(m => m.builderPluginManifest()),
3132
// rem should after css/less/sass/stylus
3233
import('../plugins/rem').then(m => m.builderPluginRem()),
3334
import('../plugins/hmr').then(m => m.builderPluginHMR()),

packages/builder/builder-shared/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ export * from './fallback';
2626
export * from './getLoaderOptions';
2727
export * from './svgo';
2828
export * from './patch';
29+
export * from './manifest';
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import type { Chunk } from 'webpack';
2+
3+
export const generateManifest = (
4+
seed: Record<string, any>,
5+
files: Array<{
6+
chunk?: Chunk;
7+
name: string;
8+
path: string;
9+
}>,
10+
entries: Record<string, string[]>,
11+
) => {
12+
const manifestFiles = files.reduce((manifest, file) => {
13+
manifest[file.name] = file.path;
14+
return manifest;
15+
}, seed);
16+
17+
const entrypointFiles = Object.keys(entries).reduce<string[]>(
18+
(previous, name) =>
19+
previous.concat(
20+
entries[name].filter(fileName => !fileName.endsWith('.map')),
21+
),
22+
[],
23+
);
24+
25+
return {
26+
files: manifestFiles,
27+
entrypoints: entrypointFiles,
28+
};
29+
};

packages/builder/builder-webpack-provider/src/plugins/manifest.ts

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { BuilderPlugin } from '../types';
2+
import { generateManifest } from '@modern-js/builder-shared';
23

34
export const builderPluginManifest = (): BuilderPlugin => ({
45
name: 'builder-plugin-manifest',
@@ -20,25 +21,7 @@ export const builderPluginManifest = (): BuilderPlugin => ({
2021
{
2122
fileName: 'asset-manifest.json',
2223
publicPath,
23-
generate: (seed, files, entries) => {
24-
const manifestFiles = files.reduce((manifest, file) => {
25-
manifest[file.name] = file.path;
26-
return manifest;
27-
}, seed);
28-
29-
const entrypointFiles = Object.keys(entries).reduce<string[]>(
30-
(previous, name) =>
31-
previous.concat(
32-
entries[name].filter(fileName => !fileName.endsWith('.map')),
33-
),
34-
[],
35-
);
36-
37-
return {
38-
files: manifestFiles,
39-
entrypoints: entrypointFiles,
40-
};
41-
},
24+
generate: generateManifest,
4225
},
4326
]);
4427
});

packages/document/builder-doc/docs/en/config/output/enableAssetManifest.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
- **Type:** `boolean`
22
- **Default:** `false`
3-
- **Bundler:** `only support webpack`
43

54
Whether to generate a manifest file that contains information of all assets.
65

packages/document/builder-doc/docs/en/guide/advanced/rspack-start.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ Unsupported configurations and capabilities include:
110110

111111
- [output.disableCssExtract](/api/config-output.html#outputdisablecssextract)
112112
- [output.disableSourcemap.css](/api/config-output.html#outputdisablesourcemap)
113-
- [output.enableAssetManifest](/api/config-output.html#outputenableassetmanifest)
114113
- [output.enableCssModuleTSDeclaration](/api/config-output.html#outputenablecssmoduletsdeclaration)
115114
- [output.enableInlineScripts](/api/config-output.html#outputenableinlinescripts)
116115
- [output.legalComments.inline](/api/config-output.html#outputlegalcomments)

packages/document/builder-doc/docs/zh/config/output/enableAssetManifest.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
- **类型:** `boolean`
22
- **默认值:** `false`
3-
- **打包工具:** `仅支持 webpack`
43

54
是否生成 manifest 文件,该文件包含所有构建产物的信息。
65

0 commit comments

Comments
 (0)