I’m using a large library (around 1 MB) along with webpack for building. The library is just used normally – it’s in package.json’s dependencies
, and at some point in my code I import it with an import from <lib_name>
(this is in Typescript).
So right now, when I run a webpack build
, the end result bundle.js
contains all (or most? not sure how much webpack trims, actually) of the library’s code. So even my barebones application that’s only a couple lines of code and an import has that big 1MB build size.
What I would like to do is have the library not be thrown into the final build, and instead basically have in my HTML file something like this:
<script src="https://some.cdn.here/thelibrary-v0.0.0.min.js"></script>
<script src="bundle.js"></script>
In other words, the files in the build would be something like:
BEFORE:
dist/
bundle.js -- 1005 KB
AFTER:
dist/
thelibrary-v0.0.0.min.js -- 1000 KB
bundle.js -- 5 KB
Where bundle.js
becomes a very small file with just my code, and it simply expects the library to be loaded beforehand. To be clear – bundle.js
would still be using things from the library and would need it to run. I’m not sure if this is actually possible or not, because I don’t have a good understanding of how webpack actually handles imports and stuff (especially in conjunction with uglify/minification). Is it possible to do something like this, and if so, how?
18977 530507Wonderful post, thank you so a lot for sharing. Do you happen to have an RSS feed I can subscribe to? 125471
907746 87696A thoughtful insight and concepts I will use on my web site. Youve obviously spent some time on this. Congratulations! 260845
168345 829041This web-site can be a walk-through rather than the info you wished about it and didnt know who ought to. Glimpse here, and you will definitely discover it. 71495
639791 579785Soon after study a couple of with the weblog articles for your site now, and that i truly like your method of blogging. I bookmarked it to my bookmark web site list and are checking back soon. Pls consider my internet website too and inform me what you consider. 353239
344155 525240hi!,I like your writing so much! share we keep up a correspondence extra approximately your post on AOL? I require a specialist on this space to solve my dilemma. Could be that is you! Searching ahead to peer you. 55333