Javascript bundler webpack

Web

Installation

1
2
3
# webpack@4.1.1
npm init -y
npm install --save-dev webpack

Basic Usage

1
2
# compile to bundle.js
npx webpack src/index.js --output dist/bundle.js

Integrate with npm project

1
2
3
4
5
6
7
8
9
10
11
vim package.json
{
...
"scripts": {
"build": "webpack"
},
...
}


npm run build

Custom config - webpack.config.js

1
2
3
4
5
6
7
8
9
const path = require('path');

module.exports = {
entry: './src/index.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist')
}
};

Reference

https://webpack.js.org/guides/getting-started/