Gulp and Grunt are JavaScript task runners, while Webpack is a bundler.
An entry point indicates which module webpack should use to begin building out its internal dependency graph.
As a rule of thumb: Use exactly one entry point for each HTML document.
Configuring the output configuration options tells webpack how to write the compiled files to disk. Note that, while there can be multiple entry points, only one output configuration is specified.
//src/client/index.js
import { handleSubmit } from './js/formHandler'
import { urlChecker } from './js/urlChecker'
export {
handleSubmit,
urlChecker
}
//webpack.[ENV].js
entry: './src/client/index.js',
output: {
libraryTarget: 'var',
library: 'Client'
},
<form class="" onsubmit="return Client.handleSubmit(event)">
npm install --save-dev css-loader ts-loader
Loaders are evaluated/executed from right to left (or from bottom to top).
While loaders are used to transform certain types of modules, plugins can be leveraged to perform a wider range of tasks like bundle optimization, asset management and injection of environment variables.
npm install --save-dev html-webpack-plugin
Mode enables webpack's built-in optimizations that correspond to each environment. The default value is production.
The webpack-dev-server is a little Node.js Express server, which uses the webpack-dev-middleware to serve a webpack bundle. It also has a little runtime which is connected to the server via Sock.js.
npm install webpack-dev-server.
//package.json
{
"scripts":{
//.....
"build-dev": "webpack-dev-server --config webpack.dev.js --open",
}
}
no webpack.config.js
npm install webpack webpack-cli
<!DOCTYPE html>
<html>
<body>
<script src="main.js"></script>
</body>
</html>
//src/index.js
document.write("From inside webpack zero config!")
webpack //generates dist/index.html
"build-prod": "webpack --config webpack.prod.js",
Terser: JavaScript parser, mangler and compressor toolkit
OptimizeCSS: webpack plugin to optimize \ minimize CSS assets.
webpack runs on Node.js version 8.x and higher.