This tutorial is a component 3 of three in ‘Webpack Superior Setup’-series.
The earlier tutorials have proven you the best way to arrange a primary internet utility with Webpack 5. Up to now, Webpack is simply used to bundle all of your JavaScript recordsdata, to transpile new JavaScript options through Babel, and to serve your bundle in growth mode through Webpack’s Improvement Server. Mainly that is all the things that is wanted to get began with creating your first internet utility.
Nonetheless, Webpack comes with a lot extra to discover. As an example, finally it’s possible you’ll need to take your undertaking to manufacturing. That is when Webpack may also help you to construct a manufacturing prepared bundle which comes with all of the optimizations on your supply code. On this tutorial, you’ll study extra about Webpack and the best way to configure it to your wants. If you do not have a primary Webpack utility at your arms, you possibly can take this one from the earlier tutorials. The ultimate superior Webpack setup could be discovered on GitHub as effectively.
Desk of Contents
Webpack’s Improvement and Manufacturing Construct
Primarily there are two modes to construct your JavaScript utility: growth and manufacturing. You’ve got used the event mode beforehand to get began with Webpack Dev Server in an area growth setting. You can also make adjustments to your supply code, Webpack bundles it once more, and Webpack Dev Server exhibits you the current growth construct in your browser.
Nonetheless, finally you need to have all of the construct recordsdata which are obligatory for deploying your internet utility in manufacturing in your internet server. Since Webpack bundles all your JavaScript supply code into one bundle.js file that’s linked in your dist/index.html file, you solely want basically these two recordsdata in your internet server to show your internet utility for anybody. Let’s examine how we are able to create each recordsdata for you.
First, you have already got the dist/index.html file. Should you open it, you already see that it makes use of a bundle.js file which is created by Webpack out of all of your JavaScript supply code recordsdata from the src/ folder.
<!DOCTYPE html>
<html>
 <head>
  <title>Whats up Webpack bundled JavaScript Undertaking</title>
 </head>
 <physique>
  <div>
<h1>Whats up Webpack bundled JavaScript Undertaking</h1>
</div>
  <script src="./bundle.js"></script>
 </physique>
</html>
Second, in case you kind
npm begin
, Webpack will create this bundle.js file on the fly which is used for the Webpack Dev Server to begin your utility in growth mode. You by no means actually see the bundle.js file your self.{
...
"scripts": {
"begin": "webpack serve --config ./webpack.config.js --mode growth",
"check": "echo "Error: no check specified" && exit 0"
},
...
}
Now let’s introduce a second npm script to really construct your utility for manufacturing. We’ll use Webpack explicitly as an alternative of Webpack Dev Server to bundle all of the JavaScript recordsdata, reuse the identical Webpack configuration from earlier than, but in addition introduce the manufacturing mode:
{
...
"scripts": {
"begin": "webpack serve --config ./webpack.config.js --mode growth",
"construct": "webpack --config ./webpack.config.js --mode manufacturing",
"check": "echo "Error: no check specified" && exit 0"
},
...
}
Should you run
npm run construct
, you will notice how Webpack bundles all of the recordsdata for you. As soon as the script went by efficiently, you possibly can see the dist/bundle.js file not generated on the fly, however created for actual in your dist/ folder.The one factor left for you is to add your dist/ folder to an internet server now. Nonetheless, as a way to test regionally whether or not the dist/ folder has all the things it is advisable run your utility on a distant internet server, use a native internet server to strive it out your self:
npx http-server dist
It ought to output an URL which you’ll be able to go to in a browser. If all the things works as anticipated, you possibly can add the dist/ folder with its content material to your internet server. Personally I favor to make use of DigitalOcean to host my static web sites and internet purposes.
Additionally word that Webpack growth and manufacturing modes include their very own default configuration. Whereas the event mode creates your supply code file with an improved developer expertise in thoughts, the manufacturing construct does all of the optimizations to your supply code.
Workouts:
- Get comfy with http-server to strive your manufacturing prepared internet utility regionally
- Host your internet utility someplace (e.g. DigitalOcean)
handle your Webpack Construct Folder
Each time you run npm run construct
, you will notice Webpack creating a brand new model of your bundle JavaScript supply code with a dist/bundle.js file. Finally your Webpack construct pipeline will grow to be extra complicated and you find yourself with greater than two recordsdata in your dist/ folder. Out of the blue the folder turns into a multitude, as a result of you do not know which recordsdata belong to the latest construct. One of the best factor can be to begin with an empty dist/ folder with each Webpack construct.
To illustrate we wished to wipe our dist/ folder with each Webpack construct. It could imply that our auto generated dist/bundle.js file can be eliminated (good), but in addition our dist/index.html file which we carried out manually (dangerous). We do not need to re-create this file by hand for each Webpack construct once more. To be able to auto generate the dist/index.html file as effectively, we are able to use a Webpack plugin. First, set up the html-webpack-plugin plugin as dev dependency out of your undertaking’s root listing:
npm set up --save-dev html-webpack-plugin
After a profitable set up, introduce the Webpack plugin in your Webpack webpack.config.js file:
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: path.resolve(__dirname, './src/index.js'),
module: {
guidelines: [
{
test: /.(js)$/,
exclude: /node_modules/,
use: ['babel-loader'],
},
],
},
resolve: {
extensions: ['*', '.js'],
},
output: {
path: path.resolve(__dirname, './dist'),
filename: 'bundle.js',
},
plugins: [new HtmlWebpackPlugin()],
devServer: {
static: path.resolve(__dirname, './dist'),
},
};
Now, run
npm run construct
once more and see the way it auto generates a brand new dist/index.html file. It comes with a default template for the way the file needs to be structured and what needs to be within the file. Nonetheless, if you wish to have customized content material on your dist/index.html file, you possibly can specify a template your self:const HtmlWebpackPlugin = require('html-webpack-plugin')
module.exports = {
...
plugins: [
new HtmlWebpackPlugin({
title: 'Hello Webpack bundled JavaScript Project',
template: path.resolve(__dirname, './src/index.html'),
})
],
...
};
Then, create a brand new src/index.html template file in your supply code folder and provides it the next content material:
<!DOCTYPE html>
<html>
<head>
<title><%= htmlWebpackPlugin.choices.title %></title>
</head>
<physique>
<div>
<h1><%= htmlWebpackPlugin.choices.title %></h1>
<div id="app">
</div>
</physique>
</html>
Notice that you simply need not specify the script tag with the bundle.js file anymore, as a result of Webpack will introduce it robotically for you. Additionally word that you do not want essentially the
id
attribute and the div container, however we’ve got used within the earlier tutorial to execute some JavaScript on it.Now, run
npm run construct
once more and see whether or not the brand new auto generated dist/index.html matches your template from src/index.html. Lastly we’ve got been in a position to create each recordsdata, dist/bundle.js and dist/index.html robotically with Webpack. This implies we are able to delete the content material of our dist/ folder with each Webpack construct. So as to take action, introduce the clean-webpack-plugin plugin:npm set up --save-dev clear-webpack-plugin
Then introduce it in your webpack.config.js file:
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
module.exports = {
...
plugins: [
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
title: 'Hello Webpack bundled JavaScript Project',
template: path.resolve(__dirname, './src/index.html'),
}),
],
...
};
Now, each Webpack construct will wipe the content material of your dist/ folder earlier than creating the brand new dist/index.html and dist/bundle.js recordsdata from scratch. Having it arrange this manner, you’ll by no means discover recordsdata from older Webpack builds in your dist/ folder which is ideal for simply taking your complete dist/ folder to manufacturing.
Notice: If you’re utilizing a model management system like GitHub, you possibly can put the construct folder (dist/) into your .gitignore file, as a result of all the things is auto generated for everybody anyway. After somebody received a replica of your undertaking, the individual can do a
npm run construct
to generate the recordsdata.Workouts:
- Watch your dist/ folder when working
npm run construct
- Regulate the src/index.html to your wants
- Take a look at extra non-obligatory configuration which are obtainable on your new Webpack plugins
Webpack Supply Maps
Webpack bundles all your JavaScript supply code recordsdata. That is excellent, nevertheless, it introduces one pitfall for us as builders. When you introduce a bug and see it in your browser’s developer instruments, it is usually tough to trace down the file the place the bug occurred, as a result of all the things is bundled into one JavaScript file by Webpack. As an example, for instance our src/index.js file imports a operate from one other file and makes use of it:
import sum from './sum.js';
console.log(sum(2, 5));
In our src/sum.js, we export this JavaScript operate however sadly launched a typo in it:
export default operate (a, b) {
return a + c;
};
Should you run
npm begin
and open the appliance in your browser, you need to see the error taking place in your developer instruments:sum.js:3 Uncaught ReferenceError: c is just not outlined
at eval (sum.js:3)
at eval (index.js:4)
at Module../src/index.js (bundle.js:457)
at __webpack_require__ (bundle.js:20)
at eval (webpack:/
at Object.0 (bundle.js:480)
at __webpack_require__ (bundle.js:20)
at bundle.js:84
at bundle.js:87
Should you click on on the sum.js file the place the error occurred, you solely see Webpack’s bundled output. Within the case of this instance, it is nonetheless readable, nevertheless think about the output for a extra complicated downside:
__webpack_require__.r(__webpack_exports__);
__webpack_exports__["default"] = (operate (a, b) {
return a + c;
});
;
Take this one step additional and introduce the bug in your Webpack construct for manufacturing as an alternative. Run
npm run construct
andnpx http-server dist
to see the error in your browser once more:bundle.js:1 Uncaught ReferenceError: c is just not outlined
at Module.<nameless> (bundle.js:1)
at t (bundle.js:1)
at bundle.js:1
at bundle.js:1
This time it is hidden in your bundle.js file with out letting you already know in regards to the precise file that is inflicting it. As well as, when you click on on the bundle.js file, you solely see Webpack’s bundled JavaScript for manufacturing which isn’t in a readable format.
In conclusion, it is not a terrific developer expertise, as a result of it turns into harder with Webpack’s bundled JavaScript recordsdata to trace down errors. That is true for growth mode, however much more for manufacturing mode.
To be able to overcome this downside, there are supply maps which could be launched to present Webpack a reference to the origin supply code. By utilizing the supply maps, Webpack can map all of the bundled supply code again to the unique supply. In your webpack.config.js file, introduce one frequent configuration for supply maps:
...
module.exports = {
...
devtool: 'source-map',
};
Afterward, with the bug nonetheless in your supply code, run
npm run construct
andnpx http-server dist
once more. In your browser, word how the bug could be tracked right down to the inflicting file sum.js:sum.js:2 Uncaught ReferenceError: c is just not outlined
at Module.<nameless> (sum.js:2)
at t (bootstrap:19)
at bootstrap:83
at bootstrap:83
Clicking on the file offers you the precise supply code and placement of the bug despite the fact that all of your JavaScript supply code received bundled by Webpack. Additionally word that there’s a new file known as dist/bundle.js.map which is used to carry out the mapping between precise supply code from src/ and the bundled JavaScript in dist/bundle.js.
Workouts:
- Introduce a couple of bugs in your supply code and bundle your undertaking with out and with supply maps to see the distinction in your browser’s developer instruments
Webpack Improvement/Construct Configuration
Up to now, we’ve got used one frequent Webpack configuration for growth and manufacturing. Nonetheless, we are able to introduce a configuration for every mode as effectively. In your bundle.json, change the beginning and construct scripts to the next:
{
...
"scripts": {
"begin": "webpack serve --config ./webpack.dev.js",
"construct": "webpack --config ./webpack.prod.js",
"check": "echo "Error: no check specified" && exit 0"
},
...
}
Now create these two new recordsdata, copy and paste the previous webpack.config.js configuration over to each of them, and delete the previous webpack.config.js file afterward. Subsequent, since we’ve got omitted the Webpack modes within the npm scripts, introduce them once more for every of your Webpack configuration recordsdata. First, the webpack.dev.js file:
...
module.exports = {
mode: 'growth',
...
};
Second, the webpack.prod.js file:
...
module.exports = {
mode: 'manufacturing',
...
};
Your npm scripts to begin and construct your utility ought to work once more. However it’s possible you’ll marvel: What is the distinction now? Apart from the Webpack modes which we handed in dynamically earlier than, the Webpack configuration is identical for growth and manufacturing. We now have even launched pointless duplication. Extra in regards to the latter one later.
In a rising Webpack configuration, you’ll introduce issues (e.g. plugins, guidelines, supply maps) which ought to behave otherwise for growth and manufacturing. As an example, let’s take the supply maps which we’ve got carried out beforehand. It is a efficiency heavy course of to create supply map recordsdata for a big code base. To be able to hold the event construct working quick and environment friendly for a terrific developer expertise, you need to have your supply maps in growth not 100% efficient because the supply maps out of your manufacturing construct. It needs to be sooner to create them for growth mode. That is why you possibly can introduce your first change for the webpack.dev.js file which isn’t mirrored in your manufacturing configuration:
...
module.exports = {
mode: 'growth',
...
devtool: 'eval-source-map',
};
Now, your supply maps are generated otherwise on your growth and manufacturing modes, as a result of they’re outlined in numerous methods in your two Webpack configuration recordsdata. This was just one occasion of getting a unique configuration for Webpack in growth and manufacturing. Sooner or later, you’ll introduce extra of them and be comfortable to should separate locations for them.
Workouts:
- Go to Webpack’s documentation to search out out extra in regards to the totally different supply map choices
Webpack Merge Configuration
For the time being, your Webpack configuration recordsdata for growth and manufacturing share plenty of frequent configuration. What if we’d be capable of extract the frequent configuration to a separate but generally used file and solely select additional particular configuration based mostly on the event and manufacturing? Let’s do it by adjusting our bundle.json file:
{
...
"scripts": {
"begin": "webpack serve --config build-utils/webpack.config.js --env env=dev",
"construct": "webpack --config build-utils/webpack.config.js --env env=prod",
"check": "echo "Error: no check specified" && exit 0"
},
...
}
As you possibly can see, we reference a brand new shared webpack.config.js for each npm scripts. The file is situated in a brand new build-utils folder. To be able to distinguish the working scripts later within the Webpack configuration, we move an setting flag (dev, prod) to the configuration as effectively.
Now, create the shared build-utils/webpack.config.js file once more, however this time within the new devoted build-utils folder, and provides it the next configuration:
const { merge } = require('webpack-merge');
const commonConfig = require('./webpack.frequent.js');
module.exports = ({ env }) => {
const envConfig = require(`./webpack.${env}.js`);
return merge(commonConfig, envConfig);
};
You may see that the operate receives our
env
setting flag from the npm script. That manner, we are able to dynamically require a setting particular Webpack configuration file with JavaScript template literals and merge it with a standard Webpack configuration. To be able to merge it, let’s set up a bit helper library:npm set up --save-dev webpack-merge
Subsequent, we’ve got to implement three recordsdata within the build-utils folder now:
- webpack.frequent.js: shared Webpack configuration for growth and construct mode.
- webpack.dev.js: Webpack configuration solely utilized by growth mode.
- webpack.prod.js: Webpack configuration solely utilized by manufacturing mode.
Let’s begin with the shared Webpack configuration in a brand new build-utils/webpack.frequent.js file:
const path = require('path');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin')
module.exports = {
entry: path.resolve(__dirname, '..', './src/index.js'),
module: {
guidelines: [
{
test: /.(js)$/,
exclude: /node_modules/,
use: ['babel-loader']
}
]
},
resolve: {
extensions: ['*', '.js']
},
plugins: [
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
title: 'Hello Webpack bundled JavaScript Project',
template: path.resolve(__dirname, '..', './src/index.html'),
})
],
output: {
path: path.resolve(__dirname, '..', './dist'),
filename: 'bundle.js'
},
devServer: {
static: path.resolve(__dirname, '..', './dist'),
},
};
Notice that some file paths have modified in distinction to the earlier Webpack configuration, as a result of we’ve got this file in a devoted folder now. Additionally word that there are not any Webpack modes and no supply maps anymore. These two choices will grow to be setting (e.g. growth, manufacturing) particular of their devoted Webpack configuration recordsdata.
Transfer on by creating the build-utils/webpack.dev.js file and provides it the next content material:
module.exports = {
mode: 'growth',
devtool: 'eval-source-map',
};
Final however not least, the brand new build-utils/webpack.prod.js file which receives the next content material:
module.exports = {
mode: 'manufacturing',
devtool: 'source-map',
};
Your folder construction needs to be just like the next now. Notice that there are not any Webpack configurations exterior of the build-utils/ folder from earlier sections anymore:
- construct-utils/
-- webpack.frequent.js
-- webpack.config.js
-- webpack.dev.js
-- webpack.prod.js
- dist/
-- bundle.js
-- bundle.js.map
-- index.html
- src/
-- index.html
-- index.js
- bundle.json
- .babelrc
That is it. Your
npm begin
andnpm run construct
scripts ought to work now. Each are working with totally different configuration for Webpack mode and supply maps in respect to their build-utils/webpack.dev.js and build-utils/webpack.prod.js configuration recordsdata. However in addition they share a standard Webpack configuration from build-utils/webpack.frequent.js. Every little thing is dynamically merged in your build-utils/webpack.config.js file which does the dynamic merging based mostly on the incoming flags out of your npm scripts within the bundle.json.Workouts:
- Revisit your build-utils/ folder with all its recordsdata and the bundle.json file
- Perceive how the instructions circulation from bundle.json to all of the recordsdata within the build-utils/ folder
- Perceive how your Webpack configuration will get merged within the build-utils/webpack.config.js
Webpack Surroundings Variables: Definition
Typically it’s possible you’ll need to know in your supply code whether or not you’re in growth or manufacturing mode. For these circumstances you possibly can specify dynamic setting variables through Webpack. Since you’ve gotten a Webpack configuration file for every setting (dev, prod), you possibly can outline devoted setting variables for them. In your build-utils/webpack.dev.js, outline a setting variable the next manner:
const { DefinePlugin } = require('webpack');
module.exports = {
mode: 'growth',
plugins: [
new DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('development'),
}
}),
],
devtool: 'eval-source-map',
};
The identical applies to your build-utils/webpack.prod.js file, however with a unique setting variable:
const { DefinePlugin } = require('webpack');
module.exports = {
mode: 'manufacturing',
plugins: [
new DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('production'),
}
}),
],
devtool: 'source-map',
};
Now you need to use (e.g.
console.log(course of.env.NODE_ENV);
) the setting variable in your src/index.js file or some other JavaScript in your src/ folder to make choices based mostly on it. On this case, you’ve gotten created two totally different setting variables — every in respect to the Webpack mode. Nonetheless, sooner or later it’s possible you’ll introduce extra setting variables for sure eventualities.Workouts:
- Take into consideration different eventualities the place setting variables can be utilized
- Is it safe to make use of delicate info in setting variables when they’re uncovered in your Webpack configuration recordsdata?
Webpack Surroundings Variables: .env
Beforehand you began to outline your setting variables in your Webpack configuration recordsdata. Nonetheless, that is not the perfect apply for delicate info. As an example, for instance you need to use API keys/secrets and techniques (credentials) to entry your database based mostly in your growth or manufacturing setting. You would not need to expose these delicate info in your Webpack configuration which can be shared with others. As a substitute, you’d need to introduce devoted recordsdata on your setting recordsdata which could be avoided others and model management programs like Git or SVN.
Let’s begin by creating two setting variables recordsdata for growth and manufacturing mode. The primary one is for growth mode and known as .env.growth. Put it in your undertaking’s root listing with the next content material:
NODE_ENV=growth
The second known as .env.manufacturing and has another content material. It is also positioned in your undertaking’s root listing:
NODE_ENV=manufacturing
By utilizing the dotenv-webpack plugin, you possibly can copy these setting variables into your Webpack configuration recordsdata. First, set up the plugin:
npm set up dotenv-webpack --save-dev
Second, use it in your build-utils/webpack.dev.js file for the event mode:
const path = require('path');
const Dotenv = require('dotenv-webpack');
module.exports = {
mode: 'growth',
plugins: [
new Dotenv({
path: path.resolve(__dirname, '..', './.env.development'),
})
],
devtool: 'eval-source-map',
};
And third, use it in your build-utils/webpack.prod.js file for the manufacturing mode:
const path = require('path');
const Dotenv = require('dotenv-webpack');
module.exports = {
mode: 'growth',
plugins: [
new Dotenv({
path: path.resolve(__dirname, '..', './.env.production'),
})
],
devtool: 'eval-source-map',
};
Now you possibly can introduce delicate info — comparable to IP addresses, account credentials, and API keys/secrets and techniques — in your setting variables through your .env.growth and .env.manufacturing recordsdata. Your Webpack configuration will copy them over to make them accessible in your supply code (see earlier part). Do not forget so as to add these new .env recordsdata to your .gitignore — if you’re utilizing model management programs (e.g. Git) — to cover your delicate info from third events.
Workouts:
- Create a .gitignore file to disregard your setting variable recordsdata in case you’re planning to make use of Git
Webpack Addons
Webpack has a big ecosystem of plugins. A number of of them are already used implicitly by utilizing Webpack growth or manufacturing modes. Nonetheless, there are additionally different Webpack plugins which enhance your Webpack bundle expertise. As an example, let’s introduce addons which can be utilized optionally to research and visualize your Webpack bundle. In your bundle.json, introduce a brand new npm script on your construct course of, however this time with Webpack addons:
{
...
"scripts": {
"begin": "webpack serve --config build-utils/webpack.config.js --env env=dev",
"construct": "webpack --config build-utils/webpack.config.js --env env=prod",
"construct:analyze": "npm run construct -- --env addon=bundleanalyze",
"check": "echo "Error: no check specified" && exit 0"
},
...
}
Notice how this new npm script runs one other npm script however with further configuration (right here Webpack addons). Nonetheless, the Webpack addons is not going to run magically. On this case, they’re solely handed as flags to our Webpack configuration. Let’s examine how we are able to use them in our build-utils/webpack.config.js file:
const { merge } = require('webpack-merge');
const commonConfig = require('./webpack.frequent.js');
const getAddons = (addonsArgs) => {
const addons = Array.isArray(addonsArgs)
? addonsArgs
: [addonsArgs];
return addons
.filter(Boolean)
.map((identify) => require(`./addons/webpack.${identify}.js`));
};
module.exports = ({ env, addon }) => {
const envConfig = require(`./webpack.${env}.js`);
return merge(commonConfig, envConfig, ...getAddons(addon));
};
Now, not solely the frequent and setting particular Webpack configuration get merged, but in addition the non-obligatory addons which we’ll put right into a devoted build-utils/addons folder. Let’s begin with the build-utils/addons/webpack.bundleanalyze.js file:
const path = require('path');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
module.exports = {
plugins: [
new BundleAnalyzerPlugin({
analyzerMode: 'static',
reportFilename: path.resolve(
__dirname,
'..',
'..',
'./dist/report.html'
),
openAnalyzer: false,
}),
],
};
Subsequent, set up the Webpack addon through npm on the command line:
npm set up --save-dev webpack-bundle-analyzer
As you possibly can see, you’ve gotten launched a selected Webpack addon, which could be optionally added, in a brand new build-utils/addons/ folder. The naming of the addon recordsdata matches the handed flag from the npm script in your bundle.json. Your Webpack merge makes certain so as to add all handed addon flags as precise addons to your Webpack configuration.
Now strive the non-obligatory device for Webpack analytics and visualization your self. In your command line, kind
npm run construct:analyze
. Afterward, test your dist/ folder for brand spanking new recordsdata. It is best to discover one which you’ll be able to open the next manner:
- Webpack’s bundleanalyze: dist/report.html
- open through
npx http-server dist
, vist the URL, and append /report.html
- open through
You will note your construct optimized Webpack bundle with two totally different visualizations. You do not have a lot code in your utility but, however when you introduce extra supply code and extra exterior libraries (dependencies) along with your node bundle supervisor, you will notice how your Webpack bundle will develop in measurement. Finally you’ll introduce a big library accidentally which makes your utility too massive. Then each analytic and visualization instruments may also help you to search out this wrongdoer.
Workouts:
- Set up a library like lodash to your utility, import it, and use a operate from it in your supply code
- Run once more
npm run construct:analyze
and test each visualizations - It is best to see that Lodash makes up an enormous a part of your Webpack bundle whereas your precise supply code takes up solely a minimal half
- Run once more
- Discover extra Webpack addons and introduce them to your utility
- You can even give you extra npm scripts for various Webpack addons
- Non-obligatory React: Take a look at the minimal React with Webpack setup
You’ve got seen how Webpack can be utilized to bundle your internet utility in a complicated manner. It lets you automate sure steps and to optimize your construct course of. You could find the completed undertaking on GitHub. You probably have some other inner plugins or libraries that you’re utilizing with Webpack, let me learn about them within the feedback under.