Now that we got webpack configured to package and bundle our js code in a single file -app.bundle.js, we need an index.html for our web app with a script tag havingsrc='app.bundle.js'.
app.bundle.js
src='app.bundle.js'
Two options:
npm install -g webpack
When installed globally, webpack can be run using webpack command from the Command prompt/Terminal window.
In the last section, we ran the webpack command (on terminal or via npm script) with two arguments:
webpack
1. the entry point of our application for webpack to start bundling modules from and
We can have webpack running in a watch mode. With watch-mode enabled, webpack will keep ‘watch’-ing for any changes we make in our code and once we save the changes, it will rerun by itself to rebuild the package.
Lets start by creating an empty project folder and initialize it for npm using npm init command
npm init
To see how webpack bundles and packages our other dependent javascript modules in the final app.bundle.js, lets create another js file and import it in our app.js
1. Under our ./src/scripts folder, create a new file named my-helper-module.js with below…
./src/scripts
my-helper-module.js
In the previous section, we imported our my-helper-module in our app.js as below:
import * as helperModule from './my-helper-module.js'
We can add a resolve block in our webpack.config so that webpack can resolve and…
Webpack, with the help of its loaders and plugins, is a Module Bundler +…
loaders
plugins,