You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/configuration/environment.md
+8-8Lines changed: 8 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -1,31 +1,31 @@
1
1
---
2
-
title: Environment
2
+
title: 环境(Environment)
3
3
contributors:
4
4
- simon04
5
5
---
6
6
7
-
Eventually you will find the need to disambiguate in your `webpack.config.js` between [development](/guides/development) and [production builds](/guides/production-build). You have (at least) two options:
The webpack CLI support specifying build environment keys via `--cli`such as `--env.production`or`--env.platform=web`. To make use of those settings, change the configuration object into a function in `webpack.config.js`:
+ compress: env.production // compress only in production build
19
+
+ compress: env.production // 只在生产环境构建时压缩
20
20
})
21
21
]
22
22
+ };
23
23
};
24
24
```
25
25
26
-
## Using environment variables
26
+
## 使用环境变量
27
27
28
-
Alternatively, the standard approach in Node.js modules can be applied: Set an environment variable when running webpack and refer to the variables using Node's [`process.env`](https://nodejs.org/api/process.html#process_process_env). The variable `NODE_ENV`is commonly used as de-facto standard (see [here](https://dzone.com/articles/what-you-should-know-about-node-env)).
Copy file name to clipboardExpand all lines: content/configuration/external-configs.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -7,9 +7,9 @@ contributors:
7
7
- tarang9211
8
8
---
9
9
10
-
webpack lets you define you configuration files in any language. The list of supported file extensions can be found at the [node-interpret](https://github.com/js-cli/js-interpret)package. webpack with the help of [node-interpret](https://github.com/js-cli/js-interpret) will run your configuration through the language of your choice.
Copy file name to clipboardExpand all lines: content/configuration/plugins.md
+7-7Lines changed: 7 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ contributors:
12
12
13
13
`array`
14
14
15
-
A list of webpack plugins. For example, when multiple bundles share some of the same dependencies, the `CommonsChunkPlugin`could be useful to extract those dependencies into a shared bundle to avoid duplication. This could be added like so:
We encourage you to have Source Maps enabled in production. They are useful for debugging and to run benchmark tests. webpack can generate inline Source Maps included in the bundles or separated files.
In your configuration, use the `devtool` object to set the Source Map type. We currently support seven types of Source Maps. You can find more information about them in our [configuration](/configuration/devtool) documentation page.
The `DefinePlugin`performs search-and-replace operations on the original source code. Any occurrence of `process.env.NODE_ENV` in the imported code is replaced by by `"production"`. Thus, checks like `if (process.env.NODE_ENV !== 'production') console.log('...')`are evaluated to `if (false) console.log('...')`and finally minified away using `UglifyJS`.
T> Technically, `NODE_ENV` is a system environment variable that Node.js exposes into running scripts. It is used by convention to determine development-vs-production behavior, by both server tools, build scripts, and client-side libraries. Contrary to expectations, `process.env.NODE_ENV`is not set to `"production"`__within__ the build script `webpack.config.js`, see [#2537](https://github.com/webpack/webpack/issues/2537). Thus, conditionals like `process.env.NODE_ENV === 'production' ? '[name].[hash].bundle.js' : '[name].bundle.js'`do not work as expected. See how to specify the [environment in webpack configuration](/configuration/environment).
You will notice three major updates to our 'prod.js' file.
245
-
* 'webpack-merge' with the 'base.js'.
246
-
* We have move 'output' property to 'base.js'. Just to stress on that point that our output property, here, is common across all our environments and that we refactored our 'prod.js' and moved it to our 'base.js', the common configuration file.
247
-
* We have defined the 'process.env.NODE_ENV' to be 'prod' using the 'DefinePlugin'. Now across the application 'process.env.NODE_ENV' would have the value, 'prod', when we build our application for production environment. Likewise we can manage various variables of our choice, specific to environments this way.
248
-
249
-
The choice of what is going to be common across all your environments is up to you, however. We have just demonstrated a few that could typically be common across environments when we build our application.
0 commit comments