Last active
September 5, 2021 11:34
-
-
Save bbrt3/58989fa50e2326f1ed93a5c8da95e7d5 to your computer and use it in GitHub Desktop.
Webpack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Benefits of using Webpack: | |
a) Interactive coding - instead of writing code, compiling, waiting and reloading, | |
we can use Hot Module Reload (HMR) which will only reload data that has changed. | |
So if we only changed one element on our site, then only that one element will recompile (NO RELOADING!) | |
b) Seamless compilation of anything - code, styles, layout, images, fonts, etc. | |
c) Consistent tooling - webpack is not tied to a particular IDE and/or OS | |
d) Modularity - write code with benefits of small modules, ship code in bundles | |
Which means that we can have common dependencies that are going to be loaded | |
e) Sophisticated bundling - bundle per page, bundle/code splitting, minify, lazy loading bundles, remove unused code | |
E.g. we are a gaming company and we have three games: A, B, C | |
We can bundle them as three separate bundles, | |
so when user comes along and wants to play game A, then only bundle of game A gets loaded! | |
f) Caching - that can be tailored to development and production separately | |
g) Customizable environments - you can easily customize builds per environment! | |
h) Source Map support - debugging in web browser! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm install webpack -D | |
npm install webpack-cli -D -y | |
// npx is shortcut for directly using dependencies | |
// -o is for specyfing output directory | |
// --mode is for specyfing which dependencies to use, in this case | |
// we use devDependencies, so mode is set to development | |
npx webpack ./app/app.js -o ./app/dist --mode development |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Polyfill is code that implements a feature on web browsers | |
that don't support the feature. | |
Polyfills allow web developers to use an API regardless of wehther or not | |
it is supported by a browser, and usually with minimal overhead. | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Webpack-stats-graph lets us draw a map of dependencies | |
https://www.npmjs.com/package/webpack-stats-graph | |
building process | |
webpack --json > stats.json | |
choco install graphviz | |
npm install -g webpack-stats-graph | |
webpack-stats-graph # by default looks for stats.json in current directory | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment