-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Docs/update concepts #1883
Docs/update concepts #1883
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,13 +9,14 @@ contributors: | |
- jimrfenner | ||
- TheDutchCoder | ||
- adambraimbridge | ||
- EugeneHlushko | ||
--- | ||
|
||
At its core, *webpack* is a _static module bundler_ for modern JavaScript applications. When webpack processes your application, it recursively builds a _dependency graph_ that includes every module your application needs, then packages all of those modules into one or more _bundles_. | ||
|
||
T> Learn more about JavaScript modules and webpack modules [here](/concepts/modules). | ||
|
||
It is [incredibly configurable](/configuration), but to get started you only need to understand four **Core Concepts**: | ||
Since v4.0.0 webpack does not require a configuration file. Nevertheless, it is [incredibly configurable](/configuration). To get started you only need to understand four **Core Concepts**: | ||
|
||
- Entry | ||
- Output | ||
|
@@ -31,7 +32,7 @@ An **entry point** indicates which module webpack should use to begin building o | |
|
||
Every dependency is then processed and outputted into files called *bundles*, which we'll discuss more in the next section. | ||
|
||
You can specify an entry point (or multiple entry points) by configuring the `entry` property in the [webpack configuration](/configuration). | ||
You can specify an entry point (or multiple entry points) by configuring the `entry` property in the [webpack configuration](/configuration). It defaults to `./src`. | ||
|
||
Here's the simplest example of an `entry` configuration: | ||
|
||
|
@@ -48,7 +49,7 @@ T> You can configure the `entry` property in various ways depending the needs of | |
|
||
## Output | ||
|
||
The **output** property tells webpack where to emit the *bundles* it creates and how to name these files. You can configure this part of the process by specifying an `output` field in your configuration: | ||
The **output** property tells webpack where to emit the *bundles* it creates and how to name these files and defaults to `./dist`. You can configure this part of the process by specifying an `output` field in your configuration: | ||
|
||
__webpack.config.js__ | ||
|
||
|
@@ -90,9 +91,7 @@ __webpack.config.js__ | |
const path = require('path'); | ||
|
||
const config = { | ||
entry: './path/to/my/entry/file.js', | ||
output: { | ||
path: path.resolve(__dirname, 'dist'), | ||
filename: 'my-first-webpack.bundle.js' | ||
}, | ||
module: { | ||
|
@@ -127,14 +126,8 @@ In order to use a plugin, you need to `require()` it and add it to the `plugins` | |
```javascript | ||
const HtmlWebpackPlugin = require('html-webpack-plugin'); //installed via npm | ||
const webpack = require('webpack'); //to access built-in plugins | ||
const path = require('path'); | ||
|
||
const config = { | ||
entry: './path/to/my/entry/file.js', | ||
output: { | ||
path: path.resolve(__dirname, 'dist'), | ||
filename: 'my-first-webpack.bundle.js' | ||
}, | ||
module: { | ||
rules: [ | ||
{ test: /\.txt$/, use: 'raw-loader' } | ||
|
@@ -154,3 +147,16 @@ There are many plugins that webpack provides out of the box! Check out our [list | |
Using plugins in your webpack config is straightforward - however, there are many use cases that are worth further exploration. | ||
|
||
[Learn more!](/concepts/plugins) | ||
|
||
|
||
## Mode | ||
|
||
By setting the `mode` parameter to either `development` or `production`, you can enable webpack's built-in optimizations that correspond with the selected mode. | ||
|
||
```javascript | ||
module.exports = { | ||
mode: 'production' | ||
}; | ||
``` | ||
|
||
[Learn more!](/concepts/mode) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this page exists (yet), so better take this out for now :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But i did add it within the pr There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh yeah, completely missed that because of the branch switch, sorry about that! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
--- | ||
title: Mode | ||
sort: 4 | ||
contributors: | ||
- EugeneHlushko | ||
--- | ||
|
||
Providing the `mode` configuration option tells webpack to use its built-in optimizations accordingly. | ||
|
||
`string` | ||
|
||
## Usage | ||
|
||
Just provide the `mode` option in the config: | ||
|
||
```javascript | ||
module.exports = { | ||
mode: 'production' | ||
}; | ||
``` | ||
|
||
|
||
or pass it as a cli argument: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CLI, uppercase |
||
|
||
```bash | ||
webpack --mode=production | ||
``` | ||
|
||
The following string values are supported: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should add a note or something clarifying that setting |
||
|
||
Option | Description | ||
--------------------- | ----------------------- | ||
`development` | Provides `process.env.NODE_ENV` with value `development`. Enables `NamedModulesPlugin`. | ||
`production` | Provides `process.env.NODE_ENV` with value `production`. Enables `UglifyJsPlugin`, `ModuleConcatenationPlugin` and `NoEmitOnErrorsPlugin`. | ||
|
||
|
||
### Mode: development | ||
|
||
|
||
```diff | ||
// webpack.production.config.js | ||
module.exports = { | ||
+ mode: 'development' | ||
- plugins: [ | ||
- new webpack.NamedModulesPlugin(), | ||
- new webpack.DefinePlugin({ "process.env.NODE_ENV": JSON.stringify("development") }), | ||
- ] | ||
} | ||
``` | ||
|
||
|
||
### Mode: production | ||
|
||
|
||
```diff | ||
// webpack.production.config.js | ||
module.exports = { | ||
+ mode: 'production', | ||
- plugins: [ | ||
- new UglifyJsPlugin(/* ... */), | ||
- new webpack.DefinePlugin({ "process.env.NODE_ENV": JSON.stringify("production") }), | ||
- new webpack.optimize.ModuleConcatenationPlugin(), | ||
- new webpack.NoEmitOnErrorsPlugin() | ||
- ] | ||
} | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would change it to: '...files, it defaults to
./dist
'