Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
9853fa2
Create new hot-module-reloading doc
jmreidy Aug 5, 2016
69fccee
First cut of HMR documentation
jmreidy Aug 5, 2016
07161de
Update project config section
jmreidy Aug 9, 2016
bee36a8
Fix spelling mistakes
jmreidy Aug 9, 2016
40a0beb
Update .babelrc section
jmreidy Aug 9, 2016
81b5eac
Make example config more consistent
jmreidy Aug 11, 2016
96e4dea
Fix typos
therobinkim Aug 20, 2016
5a63de5
Merge pull request #69 from therobinkim/therobinkim/typos
bebraw Aug 20, 2016
31dda53
add contributing.md file with instructions
jschwarty Aug 21, 2016
b190a1b
fix links, cd path, add bold styling
jschwarty Aug 21, 2016
1dabdc9
swap order of changes types to be consistent
jschwarty Aug 21, 2016
8280dcd
remove code contribs info, add develop branch info
jschwarty Aug 21, 2016
8745539
Merge pull request #72 from jschwarty/feature/add-contributing-file
TheLarkInn Aug 21, 2016
c7c5567
Update README.md
TheLarkInn Aug 21, 2016
3e0755b
docs(concepts): added new targets section (#71)
TheLarkInn Aug 24, 2016
5a2e228
Use Ubuntu Mono for code blocks
skipjack Aug 24, 2016
c4d390c
Added Long-term caching page
okonet Aug 25, 2016
838c5bb
[fix] Fixing misspelled language and adding missing commas
skipjack Aug 26, 2016
c04eb41
[fix] Minor fix in logo styling
skipjack Aug 26, 2016
1808be8
[fix] Update antwar (fixes #76)
skipjack Aug 26, 2016
b3e6d35
Documentation for webpack cli
Aug 26, 2016
fd21551
Documentation for how to develop using Vagrant
SpaceK33z Aug 27, 2016
cac8833
Add correct code lang blocks
SpaceK33z Aug 27, 2016
986004d
Implement PR feedback
SpaceK33z Aug 28, 2016
dc8ebf5
Merge pull request #78 from SpaceK33z/feature/add-develop-using-vagra…
bebraw Aug 28, 2016
ccb15a8
develop using vagrant - using -> Using, bash -> sh
bebraw Aug 28, 2016
ab0dce4
Move HMR walkthrough to React section
jmreidy Aug 29, 2016
e795740
Capitalize text for all headers
okonet Aug 30, 2016
60e8e3b
Better code formatting
okonet Aug 30, 2016
7e740b0
Merge pull request #83 from okonet/feature/text-capitalize
bebraw Aug 30, 2016
2577b71
Use webpack.io specific markup for tips and warnings
okonet Aug 30, 2016
147ae28
Added link to the original Medium article
okonet Aug 30, 2016
c661b01
Merge pull request #75 from okonet/feature/long-term-caching
bebraw Aug 30, 2016
ccdfc34
Merge caching articles
bebraw Aug 30, 2016
ce78a71
Update progress
bebraw Aug 30, 2016
6e7ed53
Fix progress color
bebraw Aug 30, 2016
60283b9
Add initial content for how-to/generate-produciton-build (#73)
riqswe Aug 30, 2016
a9f00cd
Update progress
bebraw Aug 30, 2016
c1cce0e
Add "done" sections
bebraw Aug 30, 2016
bd16791
Implements review comments
Aug 30, 2016
acd97fc
Spacing corrections
Aug 30, 2016
8c14773
Merge pull request #77 from kalcifer/develop
bebraw Aug 30, 2016
6349dc5
Fix todos
bebraw Aug 30, 2016
30b37c9
Push cli to done
bebraw Aug 30, 2016
1f2b0fe
[fix] Changing all `sh` to `bash` to fix prism unsupported language e…
skipjack Aug 31, 2016
421a25c
[fix] Updating the error catching in highlight.js for clarity
skipjack Aug 31, 2016
2eec99b
Small spelling fix in Contributing.md
skipjack Aug 31, 2016
aad86cb
Minor formatting change
skipjack Aug 31, 2016
850ec59
[fix] Preventing anything in Page from overflowing it's allowed width
skipjack Aug 31, 2016
7801bf0
Adds a how to for webpack installation
Aug 31, 2016
954c7cc
Review comments
Aug 31, 2016
6177520
Merge pull request #64 from jmreidy/content-howto-hmr
bebraw Aug 31, 2016
5de6432
State -> Stage
bebraw Aug 31, 2016
c04a950
Improve React HMR Article Naming
bebraw Aug 31, 2016
27ac882
[fix] Changing `shell`s to `bash` to prevent prism errors
skipjack Sep 2, 2016
e76fb81
Review comments
Sep 4, 2016
224859c
Merge pull request #84 from kalcifer/develop
bebraw Sep 4, 2016
2a28664
Lint through proselint
bebraw Sep 4, 2016
e418c46
[fix] Changing "sh" to "bash" to fix prism errors
skipjack Sep 4, 2016
b91b64b
Adding another shade of grey
skipjack Aug 28, 2016
8497249
Updating the base font color
skipjack Sep 4, 2016
6e7e1ad
Tweaking horizontal rule styling...
skipjack Sep 4, 2016
f63973a
feat(eslint): add eslint for markdown js codeblocks
TheLarkInn Sep 6, 2016
6a08ded
Merge pull request #97 from TheLarkInn/feature/add_eslint_to_markdown…
bebraw Sep 6, 2016
ed56f7c
Tweaking hr styling (again probably temporary)
skipjack Sep 6, 2016
340b7bd
Removing capitalization for all headers, this prevents things like "W…
skipjack Sep 6, 2016
e30e9af
Rename everything-is-a-module to modules
bebraw Sep 7, 2016
4625c3b
create CNAME file for domain
sokra Sep 7, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Documentation for webpack cli
  • Loading branch information
Pavithra K committed Aug 26, 2016
commit b3e6d35d8c51ec6e7fd4bd0c02c938f5ec0c0d87
266 changes: 261 additions & 5 deletions content/api/cli.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,264 @@
---
title: Using the CLI
title: CLI
---
> Cli call
> Cli options
> --config
## Overview

> see also [[Using the configuration]]
`webpack` provides a command line interface(cli) to configure and interact with your build.
This is mostly useful in case of early prototyping, profiling, writing npm scripts or personal customization of the build.
For proper usage and easy distribution of this configuration, webpack can be configured with `webpack.config.js`.
Any parameters sent to the CLI will map to a corresponding parameter in the config file.

## Installation

``` sh
$ npm install webpack -g
```

The `webpack` command is now available globally.

### Common Usage

``` sh
webpack <entry> [<entry>] <output>
```
| Parameter | Configuration Mapping | Explanation |
|-----------|-------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| entry | entry | A filename or a set of named filenames which act as the entry point to build your project. If you pass a pair in the form of `=` you can create an additional entry point. |
| output | output.path + output.filename | A path and filename for the bundled file to be saved in. |

#### Examples

If your project structure is as follows -
```
.
├── dist
├── index.html
└── src
├── index.js
├── index2.js
└── others.js
```

`webpack src/index.js dist/bundle.js`
This will bundle your source code with entry as `index.js` and the output bundle file will have a path of `dist` and the filename will be `bundle.js`

| Asset | Size | Chunks | Chunk Names |
|-----------|---------|-------------|-------------|
| bundle.js | 1.54 kB | 0 [emitted] | index |
[0] ./src/index.js 51 bytes {0} [built]
[1] ./src/others.js 29 bytes {0} [built]

`webpack index=./src/index.js entry2=./src/index2.js dist/bundle.js`
This will form the bundle with both the files as separate entry points.

| Asset | Size | Chunks | Chunk Names |
|-----------|---------|---------------|---------------|
| bundle.js | 1.55 kB | 0,1 [emitted] | index, entry2 |
[0] ./src/index.js 51 bytes {0} [built]
[0] ./src/index2.js 54 bytes {1} [built]
[1] ./src/others.js 29 bytes {0} {1} [built]

### Common options

<b>List all of the options available on the cli</b>
``` sh
webpack --help , webpack -h
```

<b>Build source using a config file</b>
<p>Specifies a different configuration file to pick up. Use this if you want to specify something different than `webpack.config.js`, which is the default.</p>

``` sh
webpack --config example.config.js
```

<b>Send environment variable to be used in webpack config file</b>
``` sh
webpack --env=DEVELOPMENT
```

<b>Print result of webpack as a JSON</b>
<p>In every other case, webpack prints out a set of stats showing bundle, chunk and timing details. Using this option the output can be a JSON object</p>
<p>This response is accepted by webpack's [analyse tool](http://webpack.github.com/analyse). The analyse tool will take in the JSON and provide all the details of the build in graphical form</p>

``` sh
webpack --json , webpack -j, webpack -j > stats.json
```

### Output options

This set of options allows you to manipulate certain output parameters of your build.

| Parameter | Explanation | Input type | Default value |
|------------------------------|-----------------------------------------------------------------|------------|-------------------------------------------------------|
| --output-path | The output path for compilation assets | string | Current directory |
| --output-filename | The output filename of the bundle | string | [name].js |
| --output-chunk-filename | The output filename for additional chunks | string | filename with [id] instead of [name] or [id] prefixed |
| --output-source-map-filename | The output filename for the SourceMap | string | [name].map or [outputFilename].map |
| --output-public-path | The public path for the assets | string | / |
| --output-jsonp-function | The name of the jsonp function used for chunk loading | string | webpackJsonp |
| --output-pathinfo | Include a comment with the request for every dependency | boolean | false |
| --output-library | Expose the exports of the entry point as library | string | |
| --output-library-target | The type for exposing the exports of the entry,point as library | string | var |

#### Example usage

``` sh
webpack index=./src/index.js index2=./src/index2.js --output-path='./dist' --output-filename='[name][hash].bundle.js'

| Asset | Size | Chunks | Chunk Names |
|--------------------------------------|---------|-------------|---------------|
| index2740fdca26e9348bedbec.bundle.js | 2.6 kB | 0 [emitted] | index2 |
| index740fdca26e9348bedbec.bundle.js | 2.59 kB | 1 [emitted] | index |
[0] ./src/others.js 29 bytes {0} {1} [built]
[1] ./src/index.js 51 bytes {1} [built]
[2] ./src/index2.js 54 bytes {0} [built]
```

``` sh
webpack.js index=./src/index.js index2=./src/index2.js --output-path='./dist' --output-filename='[name][hash].bundle.js' --devtool source-map --output-source-map-filename='[name]123.map'

| Asset | Size | Chunks | Chunk Names |
|--------------------------------------|---------|-------------|---------------|
| index2740fdca26e9348bedbec.bundle.js | 2.76 kB | 0 [emitted] | index2 |
| index740fdca26e9348bedbec.bundle.js | 2.74 kB | 1 [emitted] | index |
| index2123.map | 2.95 kB | 0 [emitted] | index2 |
| index123.map | 2.95 kB | 1 [emitted] | index |
[0] ./src/others.js 29 bytes {0} {1} [built]
[1] ./src/index.js 51 bytes {1} [built]
[2] ./src/index2.js 54 bytes {0} [built]
```

### Debug options

This set of options allows you to better debug the application containing assets compiled with webpack

| Parameter | Explanation | Input type | Default value |
|------------|--------------------------------------------------|------------|---------------|
| --debug | Switch loaders to debug mode | boolean | false |
| --devtool | Define source map type for the bundled resources | string | - |
| --progress | Print compilation progress in percentage | boolean | false |

### Module options

These options allow you to bind modules as allowed by webpack

| Parameter | Explanation | Usage |
|--------------------|------------------------------------|-----------------------------|
| --module-bind | Bind an extension to a loader | --module-bind /\.js$/=babel |
| --module-bind-post | Bind an extension to a post loader | |
| --module-bind-pre | Bind an extension to a pre loader | |

### Watch options

These options makes the build watch for changes in files of the dependency graph and perform the build again.

| Parameter | Explanation |
|---------------------------|---------------------------------------------------------|
| --watch, -w | Watch the filesystem for changes |
| --watch-stdin, --stdin | Exit the process when stdin is closed |
| --watch-aggregate-timeout | Timeout for gathering changes while watching |
| --watch-poll | The polling interval for watching (also enable polling) |

### Optimize options

These options allow to manipulate optimisations for a production build using webpack

| Parameter | Explanation | Plugin used |
|---------------------------|--------------------------------------------------------|--------------------------------------|
| --optimize-max-chunks | Try to keep the chunk count below a limit | LimitChunkCountPlugin |
| --optimize-min-chunk-size | Try to keep the chunk size above a limit | MinChunkSizePlugin |
| --optimize-minimize | Minimize javascript and switches loaders to minimizing | UglifyJsPlugin & LoaderOptionsPlugin |
| --optimize-dedupe | Optimize duplicate module sources in the bundle | DedupePlugin |

### Resolve options

These allow to configure the webpack resolver with aliases and extensions.

| Parameter | Explanation | Example |
|------------------------|---------------------------------------------------------|---------------------------------------------|
| --resolve-alias | Setup a module alias for resolving | --resolve-alias jquery-plugin=jquery.plugin |
| --resolve-extensions | Setup extensions that should be used to resolve,modules | --resolve-extensions .es6 .js .ts |
| --resolve-loader-alias | Minimize javascript and switches loaders to minimizing | |

### Stats options

These options allow webpack to display various stats and style them differently in the console output.

| Parameter | Explanation | Type |
|-------------------------|--------------------------------------------------------------------|---------|
| --color, --colors | Enables/Disables colors on the console [default: (supports-color)] | boolean |
| --sort-modules-by | Sorts the modules list by property in module | string |
| --sort-chunks-by | Sorts the chunks list by property in chunk | string |
| --sort-assets-by | Sorts the assets list by property in asset | string |
| --hide-modules | Hides info about modules | boolean |
| --display-exclude | Exclude modules in the output | boolean |
| --display-modules | Display even excluded modules in the output | boolean |
| --display-chunks | Display chunks in the output | boolean |
| --display-entrypoints | Display entry points in the output | boolean |
| --display-origins | Display origins of chunks in the output | boolean |
| --display-cached | Display also cached modules in the output | boolean |
| --display-cached-assets | Display also cached assets in the output | boolean |
| --display-reasons | Display reasons about module inclusion in the output | boolean |
| --display-used-exports | Display information about used exports in modules (Tree Shaking) | boolean |
| --display-error-details | Display details about errors | boolean |
| --verbose, -v | Show more details | boolean |

### Advanced options

| Parameter | Explanation | Usage |
|-----------------------|------------------------------------------------------------------|---------------------------------------------|
| --records-input-path | Path to the records file (reading) | |
| --records-output-path | Path to the records file (writing) | |
| --records-path | Path to the records file | |
| --define | Define any free var in the bundle | --define process.env.NODE_ENV='development' |
| --target | The targeted execution enviroment | --target='node' |
| --cache | Enable in memory caching [Enabled by default for watch] | --cache=false |
| --hot | Enables Hot Module Replacement [Uses HotModuleReplacementPlugin] | --hot=true |
| --prefetch | Prefetch the particular file | --prefetch=./files.js |
| --provide | Provide these modules as free vars in all modules | --provide jQuery=jquery |
| --labeled-modules | Enables labeled modules [Uses LabeledModulesPlugin] | |
| --plugin | Load this plugin | |
| --bail | Abort the compilation on first error | |

### Shortcuts

| Shortcut | Replaces |
|----------|-------------------------------------------------------------------------------------------|
| -d | --debug --devtool eval-cheap-module-source-map --output-pathinfo |
| -p | --optimize-minimize --define,process.env.NODE_ENV="production" --optimize-occurence-order |

### Profiling

This option profiles the compilation and includes this information in the stats output
It gives you an in depth idea of which step in the compilation is taking how long. This can help you optimise your build in a more informed manner.

```sh
webpack --profile

30ms building modules
1ms sealing
1ms optimizing
0ms basic module optimization
1ms module optimization
1ms advanced module optimization
0ms basic chunk optimization
0ms chunk optimization
1ms advanced chunk optimization
0ms module and chunk tree optimization
1ms module reviving
0ms module order optimization
1ms module id optimization
1ms chunk reviving
0ms chunk order optimization
1ms chunk id optimization
10ms hashing
0ms module assets processing
13ms chunk assets processing
1ms additional chunk assets processing
0ms recording
0ms additional asset processing
26ms chunk asset optimization
1ms asset optimization
6ms emitting
```