Webpack - multi-page application with a single budled js file

74 views Asked by At

I'm trying to update a legacy frontend web application to use webpack for the dependencies. Right now it's structured like so:

- login.html
- dashboard.html
... src/login.js
... src/dashboard.js

Each page has its own javascript file, plus it loads in a bunch of external dependencies via script tags on the page. My problem is that most of the pages use some variation of the same bunch of very large libraries and jquery plugins. If I bundle each page's js into a seperate js file, i'm going to end up with a huge bundle for every page that has to be downloaded every time the user changes page. I'd prefer to just have one bundle that every page loads and uses the neccessary part. Is webpack fir for purpose here, and if so how should I be going about it?

1

There are 1 answers

0
Dan Sweeney On

I "solved" this by keeping my library imports as they are, ie jquery, bootstrap etc downloaded from CDNs. I made one bundle for each of my bigger local libraries and included that on each page so that it gets cached by the browser, then I used webpack with multiple entry point for our bespoke js code.