How to add multiple chunks/entries to a generated HTML page #2290
-
Hi there! We recently started using Rsbuild at my company and it's been amazing so far, great work! export default defineConfig({
source: {
entry: {
additionalChunk: "./src/additiona-chunk",
index: "./src/core",
},
}); We'd like to have a single HTML in the output that includes both chunks/scripts. export default defineConfig({
tools: {
htmlPlugin: (htmlConfig, { entryName }) => {
if (entryName === "index") {
htmlConfig.chunks = ["additionalChunk", "index"];
htmlConfig.chunksSortMode = "manual";
}
}
}
}); But this seems rather hacky, and at the end of the day we're still generating one additional HTML file for Oh, and one more thing! I might have missed it, but is there a way to have the Thanks, and keep up with the great work! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Thank you for your support and detailed questions ❤️
I can answer this question first (it's simpler), we just need to set historyApiFallback to the specified HTML file, like this: // rsbuild.config.ts
export default defineConfig({
source: {
entry: {
foo: './src/index.jsx',
},
},
server: {
historyApiFallback: {
index: '/foo.html',
},
},
}); And there are some document for this: https://rsbuild.dev/guide/basic/server#custom-fallback-behavior |
Beta Was this translation helpful? Give feedback.
-
To add multiple entries in a single HTML page, it is recommended to use Rsbuild will support the following usage in the next release: export default defineConfig({
source: {
entry: {
index: {
import: './src/index.js',
// add pre.js to index.html
dependOn: 'pre',
},
pre: './src/pre.js',
},
},
tools: {
bundlerChain(chain, { CHAIN_ID }) {
// remove pre.html
chain.plugins.delete(`${CHAIN_ID.PLUGIN.HTML}-pre`);
},
},
});
Note that we need to use bundlerChain to remove the generated |
Beta Was this translation helpful? Give feedback.
To add multiple entries in a single HTML page, it is recommended to use
entry[].dependOn
.Rsbuild will support the following usage in the next release:
Note that we need to use bundlerChain to remove the generated
pre.html
, as Rsbuild currently does not provide configuration to remove specified HTML files.