Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(builder): support output.enableAssetManifest in Rspack #3721

Merged
merged 6 commits into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/tame-berries-exercise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@modern-js/builder-rspack-provider': patch
---

feat(builder): support output.enableAssetManifest in Rspack


feat(builder): 在使用 Rspack 构建时支持 output.enableAssetManifest 配置项
1 change: 1 addition & 0 deletions packages/builder/builder-rspack-provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"@rspack/dev-middleware": "0.0.0-canary-22b006c-20230517164249",
"@rspack/plugin-html": "0.0.0-canary-22b006c-20230517164249",
"@rspack/postcss-loader": "0.0.0-canary-22b006c-20230517164249",
"rspack-manifest-plugin": "5.0.0-alpha0",
"caniuse-lite": "^1.0.30001451",
"core-js": "~3.30.0",
"rspack-plugin-virtual-module": "0.1.0"
Expand Down
27 changes: 27 additions & 0 deletions packages/builder/builder-rspack-provider/src/plugins/manifest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { BuilderPlugin } from '../types';
import { generateManifest } from '@modern-js/builder-shared';

export const builderPluginManifest = (): BuilderPlugin => ({
name: 'builder-plugin-manifest',

setup(api) {
api.modifyBundlerChain(async (chain, { CHAIN_ID }) => {
const config = api.getNormalizedConfig();

if (!config.output.enableAssetManifest) {
return;
}

const { WebpackManifestPlugin } = await import('rspack-manifest-plugin');
const publicPath = chain.output.get('publicPath');

chain.plugin(CHAIN_ID.PLUGIN.MANIFEST).use(WebpackManifestPlugin, [
{
fileName: 'asset-manifest.json',
publicPath,
generate: generateManifest,
},
]);
});
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const applyDefaultPlugins = (plugins: Plugins) =>
import('../plugins/less').then(m => m.builderPluginLess()),
import('../plugins/sass').then(m => m.builderPluginSass()),
import('../plugins/minimize').then(m => m.builderPluginMinimize()),
import('../plugins/manifest').then(m => m.builderPluginManifest()),
// rem should after css/less/sass/stylus
import('../plugins/rem').then(m => m.builderPluginRem()),
import('../plugins/hmr').then(m => m.builderPluginHMR()),
Expand Down
1 change: 1 addition & 0 deletions packages/builder/builder-shared/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ export * from './fallback';
export * from './getLoaderOptions';
export * from './svgo';
export * from './patch';
export * from './manifest';
29 changes: 29 additions & 0 deletions packages/builder/builder-shared/src/manifest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type { Chunk } from 'webpack';

export const generateManifest = (
seed: Record<string, any>,
files: Array<{
chunk?: Chunk;
name: string;
path: string;
}>,
entries: Record<string, string[]>,
) => {
const manifestFiles = files.reduce((manifest, file) => {
manifest[file.name] = file.path;
return manifest;
}, seed);

const entrypointFiles = Object.keys(entries).reduce<string[]>(
(previous, name) =>
previous.concat(
entries[name].filter(fileName => !fileName.endsWith('.map')),
),
[],
);

return {
files: manifestFiles,
entrypoints: entrypointFiles,
};
};
21 changes: 2 additions & 19 deletions packages/builder/builder-webpack-provider/src/plugins/manifest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { BuilderPlugin } from '../types';
import { generateManifest } from '@modern-js/builder-shared';

export const builderPluginManifest = (): BuilderPlugin => ({
name: 'builder-plugin-manifest',
Expand All @@ -20,25 +21,7 @@ export const builderPluginManifest = (): BuilderPlugin => ({
{
fileName: 'asset-manifest.json',
publicPath,
generate: (seed, files, entries) => {
const manifestFiles = files.reduce((manifest, file) => {
manifest[file.name] = file.path;
return manifest;
}, seed);

const entrypointFiles = Object.keys(entries).reduce<string[]>(
(previous, name) =>
previous.concat(
entries[name].filter(fileName => !fileName.endsWith('.map')),
),
[],
);

return {
files: manifestFiles,
entrypoints: entrypointFiles,
};
},
generate: generateManifest,
},
]);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
- **Type:** `boolean`
- **Default:** `false`
- **Bundler:** `only support webpack`

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ Unsupported configurations and capabilities include:

- [output.disableCssExtract](/api/config-output.html#outputdisablecssextract)
- [output.disableSourcemap.css](/api/config-output.html#outputdisablesourcemap)
- [output.enableAssetManifest](/api/config-output.html#outputenableassetmanifest)
- [output.enableCssModuleTSDeclaration](/api/config-output.html#outputenablecssmoduletsdeclaration)
- [output.enableInlineScripts](/api/config-output.html#outputenableinlinescripts)
- [output.legalComments.inline](/api/config-output.html#outputlegalcomments)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
- **类型:** `boolean`
- **默认值:** `false`
- **打包工具:** `仅支持 webpack`

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ Builder 旨在消除不同打包工具之间的主要差异,帮助用户以较

- [output.disableCssExtract](/api/config-output.html#outputdisablecssextract)
- [output.disableSourcemap.css](/api/config-output.html#outputdisablesourcemap)
- [output.enableAssetManifest](/api/config-output.html#outputenableassetmanifest)
- [output.enableCssModuleTSDeclaration](/api/config-output.html#outputenablecssmoduletsdeclaration)
- [output.enableInlineScripts](/api/config-output.html#outputenableinlinescripts)
- [output.legalComments.inline](/api/config-output.html#outputlegalcomments)
Expand Down
Loading