I'm new to bundlers and am currently learning about Fusebox. I really like it so far except that I can't figure out how to use it for a multi-page project. So far I've only been able to find a tutorial on how to do this using webpack, not for fusebox.
Input files in src folder:
- index.html
- index2.html
- index.ts
Desired output in dist folder:
- app.js
- vendor.js
- index.html
- index2.html
Actual output in dist folder:
- app.js
- vendor.js
- index.html
Here is my config in the fuse.js file:
Sparky.task("config", () => {
fuse = FuseBox.init({
homeDir: "src",
output: "dist/$name.js",
hash: isProduction,
sourceMaps: !isProduction,
plugins: [
[SassPlugin(), CSSPlugin()],
CSSPlugin(),
WebIndexPlugin({
title: "Welcome to FuseBox index",
template: "src/index.html"
},
WebIndexPlugin({
title: "Welcome to FuseBox index2",
template: "src/index2.html"
},
isProduction && UglifyJSPlugin()
]
});
// vendor should come first
vendor = fuse.bundle("vendor")
.instructions("~ index.ts");
// out main bundle
app = fuse.bundle("app")
.instructions(`!> [index.ts]`);
if (!isProduction) {
fuse.dev();
}
});
Setting WebIndexPlugin twice within plugins doesn't work. What is the correct way to set up a multi-html page project with fusebox?
The
WebIndexPlugincan not be configured, to output more than one html file.But if you don't use a hash for the generated bundles (e.g.:
output: "dist/$name.$hash.js"), you don't need theWebIndexPlugin-- you can remove it completly from thepluginsoption. Because you already know the names of the generated bundles (vendor.jsandapp.js) you can just include the following linesinstead of the placeholder
$bundles.If you want, that both html files are copied from your
srcdirectory into yourdistdirectory, you can add the following lines to yourfuse.jsscript:Note: Don't forget to add
fs-extra:^5.0.0to yourpackage.json