Don't include a JS library in webpack build (with the assumption that it'll be included in a script tag)

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=""></script>
<script src="bundle.js"></script>

In other words, the files in the build would be something like:

    bundle.js -- 1005 KB

    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?

5 thoughts on “Don't include a JS library in webpack build (with the assumption that it'll be included in a script tag)”

  1. 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

  2. 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

  3. 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


Leave a Comment