Notice: This tutorial was written for Webpack 3, which is no longer the latest. A follow-up tutorial has been written for Webpack 4.
Back in early 2017, I wrote a blog tutorial Step-by-Step Minimalistic React Web App with Just the Bare Essentials, but at the time this is written in 2018, that tutorial has become obsolete because the instructions provided are slightly incompatible with Webpack versions 3 and 4 released since then. This new blog tutorial provides instructions on how to produce a minimalistic React app with Webpack version 3.
Most of the steps for developing a React app with Webpack 3 are exactly the same as with Webpack 1, however, some specifics are different. I list these out in the Summary section. Also, this tutorial has been developed on Ubuntu 18.04 with Node 8.10.0 and NPM 3.5.2, while the original tutorial has been developed on Ubuntu 14.04 with Node 0.10.25 and NPM 1.3.10. The old versions of Node and NPM used in the original tutorial do not support running Webpack 3.
For anybody unfamiliar with React, I recommend that you first read the following sections from the previous tutorial:
The Node.js is the runtime environment inside which all of our other tools will be running. So we need to natively install Node.js onto the operating system of the computer on which we’ll be doing our development. The official installation instructions for Node.js are here on their website.
On my Ubuntu 18.04 test machine, I just did apt-get install nodejs
with root
permissions. This installed Node 8.10.0.
So install Node.js as the first step of this tutorial. This has been documented in the example repo commit 7385fb9741dacbe96a6871d5fe134995765e7e91
.
The NPM Node Package Manager will be used to install Webpack 3 and Babel. On some OSes NPM also gets installed as a dependency of Node.js, but on my Ubuntu 18.04 test system this was not the case. I had to install it manually with apt-get install npm
with root
permissions. If you’re not on Ubuntu 18.04, please refer to the official installing NPM page. To verify that you have NPM installed, run npm -v
inside your console. I’m personally currently running NPM version 3.5.2.
This has been documented in the example repo commit 79076f9fe1d8c7b2ac76e0ed41cd874d968f3c1c
.
The Webpack module bundler, specifically version 3 for this tutorial, will manage the whole build process for our app, (including running the Babel transpiler,) so we need to install it next. This time we’ll be installing with NPM rather than with the native OS package manager. In fact, from this point on we’ll only be using NPM whenever we need to install any additional software. The NPM package for Webpack is webpack
. Run the command: npm install webpack@webpack-3
Notice that I explicitly specified the tag @webpack-3
after the package name. Had I not specified this token, NPM would likely download version 4 or some other version which is incompatible with the instructions in this tutorial.
This step is documented in the example repo commit f02496a08c034863418acef77e84f12e193b3ea2
.
At this point, a new directory node_modules/
will appear at the root of your project directory, and it will contain the logic for Webpack and all its dependencies. This directory and all its contents currently take up 73 MB on the Ubuntu 18.04 system I’m using. We don’t have to install Webpack inside our project, in fact, NPM allows installing all packages globally; however, for the purpose of this tutorial we’re installing all packages locally to get a better idea of what we need to install, and also not to mess with the global system configuration.
However, even though we’re going to keep node_modules/
locally, we’re not going to keep track of its contents with our Git repository, or at least I’m not. So I recommend you create a .gitignore
with node_modules/
in it. This is done in the example repo commit 8931cd0fa03e068a294477fd2da6972af17cb41c
Now that we have Webpack 3 installed, we could immediately continue to installing Babel, but not just yet. First, we’re going to introduce some very basic Webpack 3 configuration without Babel, and then when we install Babel, we’re going to add the Babel-specific configuration on top of that initial configuration. This way we’ll get to see only the bare minimum of what Webpack can operate with, and what Babel requires.
So Webpack is a module bundler. What that means is that it takes in several files (modules), and spits out a single file with all those modules combined. Actually the output does not always have to be a single file, but that’s what it will be for the purpose of this tutorial. We bundle several files into 1 to make the logic they contain faster for the browser to download.
By convention, we will keep our Webpack input files in the subdirectory webpack_in
, and our output file will be dumped by Webpack into webpack_out
. Our primary input files will import secondary input files, but since Webpack will start the packing with the primary files, and that’s also where the JavaScript logic interpretor will start when our code is finally executed, we will call our primary files Webpack entry files.
So by using this nomenclature, our initial entry file will be webpack_in/entry.js
. For now, all the logic it will contain will be a console log to indicate that it has been interpreted when we test it in the browser. I have prepared this initial logic in the example repo commit 10131f79a393e176b1016972c6a77b3d14b2cd75
.
OK, so now we have our basic JavaScript entry file. Next, we must tell Webpack to grab it and spit-out webpack_out/minimalistic_react.js
For now we’re processing just 1 file and outputting just 1 file, but that’s just for the sake of this tutorial, to allow us to see the most basic Webpack configuration. Pretty soon we’ll be processing a lot more input files than just one. The output file name minimalistic_react.js
is just an arbitrary name I chose.
We communicate our parameters to Webpack via a special configuration file, which we’re going to call webpack.config.js
. As can be deduced by its file extension, the configuration file itself is a JavaScript file executed by the Node.js runtime environment. I have prepared this file in the example repo commit 911e65b61d88e4dc726ab8cffdd1a9a0d10a30b8
.
As you can see, the configuration logic is only 8 lines. First, we import Node.js API path
to be able to join directory names with the host OS directory separation token. Next, we specify our entry file webpack_in/entry.js
, and then specify our output to be webpack_out/minimalistic_react.js
. And that’s all there’s to it for now!
Time to run Webpack with our just-prepared config! This is done with the command: ./node_modules/webpack/bin/webpack.js --config ./webpack.config.js
This step has been documented in the example repo commit 9e7f861253b2a1580bb8f71e35fad471216a6b17
.
From this point on it will be necessary to re-bundle our JavaScript again and again every time we change it. This is one drawback to building React-based applications. However, we can save ourselves the trouble of typing the Webpack console command each time by having Webpack “watch” our input files for changes, and re-bundle automatically when changes are detected. This is done by adding the --watch
command line parameter. To use it, open a separate terminal window in the project directory, and enter the command: ./node_modules/webpack/bin/webpack.js --config ./webpack.config.js --watch
I documented this in the commit 20b98002a0c11ce0e7bbe0ada51abaf8c983bf6d
.
The Webpack process will not exit, but will just sit there and wait for new changes. If you’ll be running Webpack in this mode, then make sure to periodically check its output for reports of any syntax errors you might accidentally introduce into your input code.
Since we just generated our output JavaScript, we’re going to have a new file webpack_out/minimalistic_react.js
. This file is currently 2873 bytes on my system, while the input file webpack_in/entry.js
is only 282 bytes. If we open the generated file, we can see that Webpack added a whole bunch of additional lines denoted by commented-out asterisks. This is normal, and since right now we’re working with a development build it is not going to be a problem. Later on in this tutorial, after we actually implement our basic React app, we’re going to experiment with minified production builds, at which time we’ll add additional Webpack configuration to prevent this superfluous generated bloat.
The generated output file is bulky and will keep changing everytime we make a change to our input files. So it makes sense to add it to .gitignore
as well to keep our Git history clean. This step has been done in the example repo commit 75931522d322a8c4dd88e9eb46130008a60bb12e
.
OK, so since now we have our generated JavaScript file, it’s time to test it with an HTML test page! I just added one with the example repo commit d96f88a615839a673cc7530ef1cacd84d62f5ddf
, and we can try it here.
This page will not look like much, as it should because it does not have much, but if we open the browser web inspector and look inside the JavaScript Console tab, we will see that our test page just emitted the string “JavaScript entry logic.” to the console. That’s exactly what we want to see, as that indicates that the logic inside that entry JavaScript file from step 5 has been packed by Webpack into its generated output, picked-up by our test page, and interpreted by the browser. Our basic Webpack configuration and build infrastructure up to this point is working!
The one crucial detail about this page is that it loads the generated JavaScript webpack_out/minimalistic_react.js
not inside the <head>
tag as is so common with using <script>
tags, but at the very bottom of the <body>
tag. There is an important reason for this — when we ultimately implement our React app, it will need to render itself into its root container element, We need to load our React JavaScript after the browser renders this root container element to be able to find it from our React logic. Without it, we will not be able to render our React app. Had we had this <script>
inside the <head>
our test page would still work for now, but it would not be suitable for when we will need for it to work with React. So remember, always load your React JavaScript at the bottom of <body>
!
At this point our infrastructure is capable of processing only the regular browser-safe ES5 JavaScript, not the ES6+/JSX we need to start developing with React. Webpack is just a packer, and it does not know how to translate from ES6+/JSX to ES5 just by itself. To do that, it needs the Babel transpiler. It’s finally time to install Babel!
Once again we’ll be using NPM, this time to install 2 packages — babel-core
and babel-loader
. (For the Webpack 1 setup in the previous tutorial, it was only necessary to install babel-loader
). The command for that is: npm install babel-core babel-loader
(or 2 separate commands npm install babel-core
and npm install babel-loader
). This is documented in the example repo commit b555694e43d3c44d7d05eca3f2f2b7841b1e88f7
. At this time the size of my node_modules
subdirectory is 100 MB, and previously it was 73.
We have Babel installed, but Webpack does not know about it yet. To tell Webpack to use Babel to transpile ES6+/JSX, we need to tell it to do so in that Webpack configuration file we worked with earlier in step 6 — webpack.config.js
. I did this in the example repo commit 82cfbe5e03ad314d28fb2a1351ea92a4e4de441d
.
If you look at this configuration diff, you’ll see that all we’re saying is that we want Webpack to “load” files with the file extension .jsx
through Babel. Regular .js
files will not be going through Babel. This is the Airbnb nomenclature approach, and contrary to Facebook which likes to reuse the .js
extension for files containing JSX logic.
Alright, so we just told Webpack to load .jsx
files through Babel, but we don’t have any .jsx
files yet! So let’s create webpack_in/entry.jsx
for our future ES6/JSX logic! I just did this in the example repo commit 8ef27f9b8b0c1fbc37a4236b5a8fd0c475ac394c
.
Whereas I had entry.js
emit the text “JavaScript entry logic” to the console log, I made entry.jsx
emit “JSX entry logic”. When we finally test this in a web browser that’s how we’ll know that our configuration is working.
Now we have told Webpack to use Babel for .jsx
files, we have created our webpack_in/entry.jsx
, but we still need to tell Webpack to actually pack that new file. Just like with webpack_in/entry.js
, we must add webpack_in/entry.jsx
to the entry
array in webpack.config.js
. I did this in the example repo commit 9d65e39638dc5d78b60868b908dc6a89d0662790
.
It’s time to run ./node_modules/webpack/bin/webpack.js --config ./webpack.config.js
to pack our JS and JSX files together, deploy the test page, and test it with a web browser! This will verify that everything we did up to now is working. I just deployed it here.
If you look in the browser console log, you’ll see that there are now 2 entries, the 1st for JavaScript, and the 2nd for JSX. This verifies that the logic in both of our entry files is reaching the browser, which is exactly what we want.
We’re almost ready to work with React, but still not quite there yet. As it turns out, to tell Babel that we actually want to translate ES6+ and JSX, we must specify certain “presets“. These presets
are referred to by the tokens env
and react
. The former is for ES6+ (for Webpack 1 in the previous tutorial, preset es2015
was used instead as ES6 and ES2015 are synonymous terms, but since ES6 was followed by ES7/8/9, the Babel people decided to deprecate the old es2015
preset and have all these just be handled by the one all-encompassing preset env
.), and the later is for JSX. Before we can even specify these presets in the configuration, we have to install their NPM modules, with the commands: npm install babel-preset-env
and npm install babel-preset-react
(These tokens can be combined into a single NPM command, but I’m listing 2 commands for better clarity.) I documented this in the example repo commit 729c209a291867e1e562f2e4311534d32a4b356b
.
My local node_modules
folder grew from 100 MB to 112 MB and 113 MB after completing this step.
And now we need to add the Babel / Webpack configuration to use the presets. I just did this in the example repo commit ab77c4dba397e64b696d9d6307f8ec011f7a871e
. As you can see this is another relatively minor addition of just 3 lines. In fact our whole Webpack configuration file is only 24 lines long, and that’s including the comment header and the blank separator lines. Our configuration is at the minimum it can be, plus now we’ve got our project infrastructure up to the point where we’re ready to work with React!
The first thing we need to do to work with React is install the NPM modules react
and react-dom
with the commands: npm install react
and npm install react-dom
I have documented this in the example repo commit 0b09e497f32c651391c9cf81b4b9cf4d9b5c5287
.
After installing these modules, my node_modules/
folder grew from 113 MB to 132 MB.
Next, we need to prepare our future React app root container element inside our test page. The container element is nothing but an empty opening and closing tag that we will specify to React DOM to render our app in. The way React DOM works is that it dumps the previously discussed virtual DOM into this container element. Any previous contents of this container element will get deleted when React DOM does this, so that’s why we’re going to just have an opening and a closing tag.
I’m going to specify a tag id
for this container to be able to use the ancient document.getElementById(...)
browser API call to obtain a reference to the element to feed to React DOM. This is how it is normally done when deploying a React app inside a web page. Using the raw DOM API has waned in popularity over the past decade in favor of using the much more flexible and comprehensive jQuery API; however, while still possible, using jQuery is frowned upon when developing with React. And this is actually the only direct DOM API call that we will be making.
Using jQuery inside React apps is frowned upon because while jQuery is all about the DOM, React has the completely opposite philosophy of never touching the real DOM except when obtaining the root container element as we’re doing right now, or rendering to it from its virtual DOM. Had we included jQuery into our project, at least for the purposes of this demo, it would end up as mostly dead code, needlessly eating up space and bandwidth. There’s nothing remarkable our test app will be doing to need jQuery.
The container element itself can be any tag, and for this tutorial I’m just going to use a plain <div>
with an id
of react-app
. I implemented this in the example repo commit e731552210338480c2d98218b9fb8f98b193d294
.
The most crucial detail in this step is that the root container element needs to be above the <script>
tag loading the React app JavaScript logic. This is so that this element is rendered before the JavaScript logic does that document.getElementById(...)
call to obtain a reference to it. Otherwise there would be no element to obtain a reference to, and therefore nowhere to render our app into. This has been discussed earlier in step 9 of the build infrastructure preparation procedure in which we explicitly placed that <script>
tag just before closing the <body>
of our test page.
And at this point we’re ready to start writing our React app inside webpack_in/entry.jsx
! I just did that in the commit 1a76c3c50db45485b84bb40c9a35567a9eb9b827
.
Staying true to the name of this tutorial, I made the app absolutely as minimalistic as it can be — all it does is render a <div>
containing the text “Hello! I’m a React app!!”, and this is all accomplished using just 3 lines of code.
react
.react-dom
.ReactDOM.render(...)
to render the JSX markup for our app into the root container element.
You may be wondering why I did not make it 2 lines rather than 3 by omitting the import of react
, since I don’t actually call its API directly in this initial implementation. It turns out that this import is a necessary dependency for the method ReactDOM.render(...)
to work. In any case, by convention we use that method to render the JSX markup for our root widget, but have that root widget be defined separately using the react
package API, so if we were to continue developing this app we would be working directly with that package as well.
Now that we have the webpack_in/entry.jsx
ES6/JSX logic for our app ready, we need to transpile it to webpack_out/minimalistic_react.js
ES5 logic, deploy it, and test it in a web browser. As before, we build / transpile with the command ./node_modules/webpack/bin/webpack.js --config ./webpack.config.js
, and upon deployment our app looks like this.
Upon looking at the app test page we will see the string “Hello! I’m a React app!!” rendered into the DOM into that root container element <div>
we prepared in step 1. If we look into the web inspector console, we will see the line “JavaScript entry logic.” followed by “JSX entry logic.” This confirms that our entry logic has been transpiled properly.
You may also see a console message “Download the React DevTools for a better development experience” followed by a URL or similar. Facebook has created an additional in-browser debugging tool for React applications, offers it as browser extensions, and also inserted special logic into the React DOM toolkit to promote it via the console log on non-production builds when the browser extension has not been detected. If you install this extension into your browser this informational message will no longer be emitted, and you will instead get a new “React” tab in the browser’s web inspector when you view pages that use React. This React tab will let you inspect React components of a React app in a similar fashion to the DOM Inspector. You can try it out on the current test page (but you’ll see only its one and only component) and on other web sites currently known to use React DOM directly, such as Instagram and Airbnb.
Another interesting thing worth mentioning is that our webpack_out/minimalistic_react.js
is currently 790 KB (at least for me), and all we’re doing is rendering a single line! Server-side gzip compression, if enabled on the web server, can compress this down to 194 KB of actual download size, but it is still quite a hefty chunk. Obviously this bloat is not from our 3 lines of code, but from all the React logic underneath. The silver lining here is that this download size will not grow by much as we add more of our own logic to the app. Nevertheless, this is still unacceptable for a production build, which is OK, because this was a development build. Doing a development build included a lot of extra debugging logic into our JavaScript, and also left it unminified. We can significantly cut down on this bloat and minify things if we do a production build, which is what we’re going to do next.
So 790 KB raw / 194 KB gzipped is a little too much for production, and we need to slim it down. Since we’re building our releases with Webpack, we’ll once again be working with the Webpack configuration file webpack.config.js
to add settings to do a production build.
The required modifications to the Webpack config are relatively minor. We will tell Webpack to (1) define our build environment as “production” and (2) to minify the output ES5. There are some additional measures that can be taken to slim it down some more, but since this is a minimalistic tutorial we’ll stick to these 2 for now. (In the previous tutorial I also used the Webpack DedupePlugin
plugin, but since then it has been deprecated and removed from Webpack.) No additional NPM installs will be required for what we’re doing. And I just committed the webpack.config.js
production configuration changes to 9f63bc92d661449b373fb836af0d14c47f3f7989
.
Now that we have changed our Webpack configuration for production, it is time to run it again to do our production build. One caveat here is that the console command to do the build has changed. We must now include the -p
parameter. So our new build command looks like this: ./node_modules/webpack/bin/webpack.js -p --config ./webpack.config.js
Furthermore, the Webpack ‘watch’ command used earlier to have it auto-bundle our code whenever we change it in the course of development is no longer applicable in the production branch, so I removed it from the production branch build instructions.
I have documented these changes to the build instructions for production with the commits 3a33b5423bf8c0938d227613e8f1cc494ec88388
and 3c3fb2de17c4ac19b176828a03bf00d06f590296
.
Our new webpack_out/minimalistic_react.js
is now 101 KB raw size. That’s still not too small, but over 7 times smaller than what it used to be. Let’s test the new production build here.
So everything still works, the React DevTools promotion is no longer appearing even if the browser plugin is not installed, and, best of all, our downloaded web server auto-gzipped size is now 32 KB. That’s pretty efficient!
It can be argued that React has made the traditional JavaScript toolkits obsolete, and it can now also be argued that React DOM has in turn been obsoleted by some of its drop-in replacements that appeared over the last couple of years. What is a React DOM drop-in replacement? It’s a toolkit duplicating the React API and its philosophy of virtual DOM in the sense that it behaves just like React, but with a different implementation. Why would there be a need for such a toolkit? Well, as discussed in the previous section, using React in a web app can result in relatively large ES5 output file size. Preact is a React API clone that can be substituted into a React web app in place of React without having to rewrite any app logic, and provide the benefit of having much smaller ES5 output file size.
Preact is just one of many React API clones / drop-in replacements. There’s also another such toolkit called Inferno, but in this tutorial we’re going to be working with Preact to see how much smaller we can get our webpack_out/minimalistic_react.js
.
The first thing we need to do to get started with Preact is to install its NPM modules preact
and preact-compat
. The later is what duplicates the React API to use the former. We’re going to install these modules with the command: npm install preact preact-compat
I’ve documented this in the example repo commit 7284c2849bf977800582ed4c7a80bf18f128a93b
. Notice that I did not remove the instructions for installing React and React DOM. These are useful to keep in case we run into some weird future problem in the course of our app development, and decide to temporarily go back to the regular React to check if the problem could be caused by the drop-in replacement. (If we wanted to get really fancy, we could set up automated integration tests to verify the performance of our build under multiple environments.)
The size of the node_modules/
on my development machine was 132 MB before I installed Preact, and it was 135 MB after.
Now that we have installed Preact, we need to tell Webpack to actually use it. So we modify our good old webpack.config.js
to substitute Preact for React. I just did that in the example repo commit 615d415133cc8a8adabda245dfc497fa4a9c1b29
. As you can see, I “alias”-ed Preact in. Now when Webpack will be trying to get React it will actually be getting Preact. The key take-away here is that I did not have to modify anything in entry.jsx
where the actual React web app lives, and if we ever want to go back, we can just comment-out these 6 lines, and we’ll be back with the plain React. It’s incredibly easy!
OK, time to run ./node_modules/webpack/bin/webpack.js --config ./webpack.config.js
to test our app with Preact. We’re doing a regular development build for now. And the output webpack_out/minimalistic_react.js
on my machine is now 90 KB raw size, while the raw size with React was 790 KB. We can look at the Preact development build test page here to see that everything still works, except that the React DevTools no longer finds our app. Preact eliminated the DevTools linkage for maximum efficiency, but if we need to debug our app again we can just temporarily comment-out that alias in Webpack config.
Our gzipped development build turned out to be 23.8 KB, while with React it was 194 KB. Who needs production builds! Well, we still do, it’s just that our current minimalistic app only renders a single <div>
.
Our evaluation of Preact would not be complete without a production build. This is exactly the same as configuring a React production build. Just as before, we need to modify the Webpack config to do the 2 additional steps outlined in step 1 of the React production section. I just cherry-picked that commit as 7f174734f4bb5a5ba28f5597780b3e0a43a4860b
.
Same as for a React production build, we have to modify our BUILD_INSTRUCTIONS
to remove the Webpack watch command, and to pass the -p
flag to Webpack. I just cherry-picked these build instructions commits as eb9fed457b9da1654444cd8311e006f6772a051c
and a0708d3e107f0e2aeb1c5c1f87b0a2d74c066b7c
. For formality here’s the full command: ./node_modules/webpack/bin/webpack.js -p --config ./webpack.config.js
.
And the Preact production output of webpack_out/minimalistic_react.js
on my system is currently 22 KB. If we test this build here we can see that our downloaded gzipped size is 7.8 KB !!! As a disclaimer I should mention that I’m not affiliated with either Preact or React and I was not paid to write this blog.
So far I went through everything step by step for the sake of clarity and demonstration, to give you the best idea of all the distinct elements required to get up and running with React; however, not all of the manual steps mentioned are absolutely necessary. This is especially true for manually installing the numerous NPM packages we installed as part of this tutorial. In fact we can list-out our packages in a configuration file called package.json
, and install all of them with a single command of: npm install
Another reason why this is useful is because package names, dependencies, and compatibilities change over time. The NPM packages outlined in this blog will mutate, and sooner or later will accumulate changes that will break the procedure outlined in this tutorial, (just as happened with the previous tutorial for Webpack 1.) The NPM configuration file package.json
allows us to lock-in package versions, giving us an immutable reference to a known working state of our dependencies.
We can use the NPM command node init
to generate our package.json
. This utility was initially built to publish NPM packages onto the NPM public repository, and for that reason it prompts the user and includes in its output some additional information that I’m going to cut out for now. And so I’ve added package.json
as git commit 6024f176cb2ca0b7bf6853ff615d3acdab757ddc
into the Preact development branch, and modified the BUILD_INSTRUCTIONS
in git commit 4010096816b06fd31f301f41d9621104df7141dd
.
Unfortunately, node init
does not differentiate between runtime dependencies and development dependencies. Runtime dependencies are those that are included from within the project application logic, and the logic within these dependencies is invoked during runtime (such as to render the app as React does in this case). Development dependencies are those that are not included from within the application logic, but are needed to bundle, deploy, or debug the application, and so on. In this project, the runtime dependencies are:
While the development dependencies are:
As can be seen in the commit 6024f176cb2ca0b7bf6853ff615d3acdab757ddc
, I manually separated the development dependencies under the separate field devDependencies
. This provides a better separation as to what is needed for what, and makes it easier to reuse this project in other projects, as the development dependencies of a dependency do not need to be pulled in.
The example repo is at https://github.com/maratbn/example_step_by_step_minimalistic_react_app and can be cloned and used as a boilerplate for a new React app. The repo contains commits for this tutorial as well as the previous tutorial on using Webpack 1, but the commits are separated across different branches. The branches that apply to this tutorial all begin with webpack3
. These additional Webpack 3 specific branches are:
webpack3
— Common configuration logic and commits.webpack3--package.json
— Just like webpack3
, but with package.json
.webpack3--production
— Just like webpack3
, but with additional changes to webpack.config.js
and BUILD_INSTRUCTIONS
to produce minimized bundles intended for deployment to production.webpack3--production--package.json
— Just like webpack3--production
, but with package.json
.webpack3--preact
— Just like webpack3
, but with Preact swapped-in for React.webpack3--preact--package.json
— Just like webpack3--package.json
, but with Preact.webpack3--preact--production
— Just like webpack3--production
, but with Preact.webpack3--preact--production--package.json
— Just like webpack3--production--package.json
, but with Preact.
If you want to use the example repo for your boilerplate, I recommend you base your project off the branch webpack3--package.json
or webpack3--preact--package.json
. When you want to deploy to production, fork-off a new release branch, and cherry-pick the production-optimizing commits from webpack3--production--package.json
or webpack3--preact--production--package.json
.
In this tutorial I went over setting up a minimalistic React app with Webpack 3. The differences in procedure between this and the procedure in the Webpack 1 tutorial are:
@webpack-3
if not using package.json
.
babel-core
had to be explicitly installed in addition to babel-loader
.
babel-preset-env
had to be used instead of babel-preset-es2015
.
DedupePlugin
could not be used as it is not available in Webpack 3.
There were no changes to the actual React app implementation, even though in this tutorial we’re using newer React packages. Also, the production bundle size for the pure (non-Preact) React app went down slightly to 101 KB raw size from 140 KB in the previous tutorial.
Copyright (c) 2010-2018 Marat Nepomnyashy
Except where otherwise noted, this webpage is licensed under a Creative Commons Attribution 3.0 Unported License.
Background wallpaper by Patrick Hoesly, used under Creative Commons Attribution 2.0 Generic License.