Skip to content

Commit 609f5ff

Browse files
committed
Merge remote-tracking branch 'upstream/cn' into cn
2 parents 3f1ef08 + 5a7aaf8 commit 609f5ff

File tree

8 files changed

+153
-40
lines changed

8 files changed

+153
-40
lines changed

components/splash-viz/splash-viz-style.scss

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
@import 'functions';
2+
@import 'vars';
23
@import 'mixins';
34

45
.splash-viz {
5-
position:relative;
6-
display:flex;
7-
height:calc(100vh - 55px);
8-
min-height:320px;
9-
max-height:720px;
10-
background:getColor(elephant);
6+
position: relative;
7+
display: flex;
8+
height: calc(100vh - 55px);
9+
min-height: 320px;
10+
max-height: 720px;
11+
background: getColor(elephant);
1112
flex-direction: column;
1213

1314
&__heading {
@@ -28,8 +29,9 @@
2829
right: 0;
2930
top: 0;
3031
bottom: 0;
31-
width: 65vw;
32+
width: 75vw;
3233
min-width: 550px;
34+
max-width: map-get($screens, large);
3335
margin: auto;
3436
display: none;
3537

content/configuration/target.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ webpack 能够为多种环境或 _target_ 构建编译。想要理解什么是 t
2020
| `target` | 描述 |
2121
| ------------- |------------------------|
2222
| `async-node`| 编译为类 Node.js 环境可用(使用 fs 和 vm 异步加载分块) |
23-
| `electron` | 编译为 [Electron](http://electron.atom.io/) 渲染进程,使用 `JsonpTemplatePlugin`, `FunctionModulePlugin` 来为浏览器环境提供目标,使用 `NodeTargetPlugin``ExternalsPlugin` 为 CommonJS 和 Electron 内置模块提供目标。 |
24-
| `electron-renderer` | [Electron](http://electron.atom.io/) `renderer-process` 编译。 |
25-
| `"node"` | 编译为类 Node.js 环境可用(使用 Node.js `require` 加载分块|
23+
| `electron` | `electron-main` 的别名 |
24+
| `electron-main` | 编译为 [Electron](http://electron.atom.io/) 渲染进程,使用 `JsonpTemplatePlugin`, `FunctionModulePlugin` 来为浏览器环境提供目标,使用 `NodeTargetPlugin``ExternalsPlugin` 为 CommonJS 和 Electron 内置模块提供目标。 |
25+
| `node` | 编译为类 Node.js 环境可用(使用 Node.js `require` 加载 chunk|
2626
|`node-webkit`| 编译为 Webkit 可用,并且使用 jsonp 去加载分块。支持 Node.js 内置模块和 [`nw.gui`](http://docs.nwjs.io/en/latest/) 导入(实验性质) |
2727
|`web`| 编译为类浏览器环境里可用**(默认)** |
2828
|`webworker`| 编译成一个 WebWorker |

content/guides/tree-shaking.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
title: Tree Shaking
33
contributors:
44
- simon04
5+
- zacanger
56
---
67

7-
_Tree shaking_ is a term commonly used in the JavaScript context for dead-code elimination, or more precisely, life-code import. It relies on ES6 module [import](https://developer.mozilla.org//en-US/docs/Web/JavaScript/Reference/Statements/import)/[export](https://developer.mozilla.org//en-US/docs/Web/JavaScript/Reference/Statements/export) for the [static structure](http://exploringjs.com/es6/ch_modules.html#static-module-structure) of its module system. The name and concept have been popularized by the ES6 module bundler [rollup](https://github.com/rollup/rollup).
8+
_Tree shaking_ is a term commonly used in the JavaScript context for dead-code elimination, or more precisely, live-code import. It relies on ES6 module [import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import)/[export](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export) for the [static structure](http://exploringjs.com/es6/ch_modules.html#static-module-structure) of its module system. The name and concept have been popularized by the ES6 module bundler [rollup](https://github.com/rollup/rollup).
89

910
webpack 2 comes with a built-in support for ES6 modules (alias *harmony modules*) as well as unused module export detection.
1011

content/plugins/commons-chunk-plugin.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ T> The deprecated webpack 1 constructor `new webpack.optimize.CommonsChunkPlugin
5858
Generate an extra chunk, which contains common modules shared between entry points.
5959
6060
```javascript
61-
new CommonsChunkPlugin({
61+
new webpack.optimize.CommonsChunkPlugin({
6262
name: "commons",
6363
// (the commons chunk name)
6464

@@ -89,7 +89,7 @@ entry: {
8989
vendor: ["jquery", "other-lib"],
9090
app: "./entry"
9191
}
92-
new CommonsChunkPlugin({
92+
new webpack.optimize.CommonsChunkPlugin({
9393
name: "vendor",
9494

9595
// filename: "vendor.js"
@@ -113,7 +113,7 @@ Hint: In combination with long term caching you may need to use the [`ChunkManif
113113
With Code Splitting multiple child chunks of a chunk can have common modules. You can move these common modules into the parent (This reduces overall size, but has a negative effect on the initial load time. It can be useful if it is expected that a user need to download many sibling chunks).
114114
115115
```javascript
116-
new CommonsChunkPlugin({
116+
new webpack.optimize.CommonsChunkPlugin({
117117
// names: ["app", "subPageA"]
118118
// (choose the chunks, or omit for all chunks)
119119

@@ -130,7 +130,7 @@ new CommonsChunkPlugin({
130130
Similar to the above one, but instead of moving common modules into the parent (which increases initial load time) a new async-loaded additional commons chunk is used. This is automatically downloaded in parallel when the additional chunk is downloaded.
131131
132132
```javascript
133-
new CommonsChunkPlugin({
133+
new webpack.optimize.CommonsChunkPlugin({
134134
// names: ["app", "subPageA"]
135135
// (choose the chunks, or omit for all chunks)
136136

@@ -156,7 +156,7 @@ The `count` property represents how many chunks the `module` is used in.
156156
This option is useful when you want to have fine-grained control over how the CommonsChunk algorithm determins where modules should be moved to.
157157
158158
```javascript
159-
new CommonsChunkPlugin({
159+
new webpack.optimize.CommonsChunkPlugin({
160160
name: "my-single-lib-chunk",
161161
filename: "my-single-lib-chunk.js",
162162
minChunks: function(module, countOfHowManyTimesThisModuleIsUsedAcrossAllChunks) {

content/plugins/define-plugin.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
---
22
title: DefinePlugin
3+
contributurs:
4+
- simon04
35
---
46

57
``` javascript
68
new webpack.DefinePlugin(definitions)
79
```
810

911
允许你创建一个在编译时可以配置的全局常量。这可能会对开发模式和发布模式的构建允许不同的行为非常有用。比如,你可能会用一个全局的常量来决定 log 在开发模式触发而不是发布模式。这仅仅是 `DefinePlugin` 提供的便利的一个场景。
10-
12+
1113

1214
**示例:**
1315

@@ -64,6 +66,25 @@ if (true) {
6466
console.log('Production log')
6567
```
6668

69+
## Use Case: Feature Flags
70+
Enable/disable features in production/development build using [feature flags](https://en.wikipedia.org/wiki/Feature_toggle).
71+
72+
```javascript
73+
new webpack.DefinePlugin({
74+
'NICE_FEATURE': JSON.stringify(true),
75+
'EXPERIMENTAL_FEATURE': JSON.stringify(false)
76+
})
77+
```
78+
79+
## Use Case: Service URLs
80+
Use a different service URL in production/development builds:
81+
82+
```javascript
83+
new webpack.DefinePlugin({
84+
'SERVICE_URL': JSON.stringify("http://dev.example.com")
85+
})
86+
```
87+
6788
***
6889

6990
> 原文:https://webpack.js.org/plugins/define-plugin/

content/plugins/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
title: Plugins
33
contributors:
44
- simon04
5+
- gonzoyumo
56
---
67

78
webpack has a rich plugin interface. Most of the features within webpack itself use this plugin interface. This makes webpack **flexible**.
@@ -14,6 +15,7 @@ webpack has a rich plugin interface. Most of the features within webpack itself
1415
|[`CompressionWebpackPlugin`](/plugins/compression-webpack-plugin)|Prepare compressed versions of assets to serve them with Content-Encoding|
1516
|[`I18nWebpackPlugin`](/plugins/i18n-webpack-plugin)|Adds i18n support to your bundles|
1617
|[`HtmlWebpackPlugin`](/plugins/html-webpack-plugin)| Simplifies creation of HTML files (`index.html`) to serve your bundles|
18+
|[`NormalModuleReplacementPlugin`](/plugins/normal-module-replacement-plugin)|Replaces resource that matches a regexp|
1719

1820

1921
![Awesome](../assets/awesome-badge.svg)
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
---
2+
title: NormalModuleReplacementPlugin
3+
contributors:
4+
- gonzoyumo
5+
---
6+
## Install
7+
8+
The `NormalModuleReplacementPlugin` is a built-in webpack plugin.
9+
10+
11+
## Usage
12+
13+
``` javascript
14+
new webpack.NormalModuleReplacementPlugin(resourceRegExp, newResource)
15+
```
16+
17+
The `NormalModuleReplacementPlugin` allows you to replace resources that match `resourceRegExp` with `newResource`. If `newResource` is relative, it is resolved relative to the previous resource. If `newResource` is a function, it is expected to overwrite the request attribute of the supplied resource.
18+
19+
This can be useful for allowing different behaviour between builds.
20+
21+
## Basic example
22+
23+
Replace a specific module when building for development environment ([read more](/configuration/environment)).
24+
25+
26+
Say you have a config file `some/path/config.development.module.js` and a special version for production in `some/path/config.production.module.js`
27+
28+
Just add the following plugin when building for production:
29+
30+
``` javascript
31+
new webpack.NormalModuleReplacementPlugin(
32+
/some\/path\/config\.development\.js/,
33+
'./config.production.js'
34+
);
35+
```
36+
37+
## Advanced example
38+
39+
Conditional build depending on an environment var ([read more](/configuration/environment)).
40+
41+
Say you want a configuration with specific values for different build targets.
42+
43+
``` javascript
44+
module.exports = function(env) {
45+
var appTarget = env.APP_TARGET || 'VERSION_A';
46+
return {
47+
plugins: [
48+
new webpack.NormalModuleReplacementPlugin(/(.*)-APP_TARGET(\.*)/, function(resource) {
49+
resource.request = resource.request.replace(/-APP_TARGET/, `-${appTarget}`);
50+
})
51+
]
52+
}
53+
54+
}
55+
```
56+
57+
Create the two config files:
58+
59+
**app/config-VERSION_A.js:**
60+
``` javascript
61+
export default {
62+
title : 'I am version A'
63+
}
64+
```
65+
**app/config-VERSION_B.js:**
66+
``` javascript
67+
export default {
68+
title : 'I am version B'
69+
}
70+
```
71+
Then import that config using the keyword you're looking for in the regexp:
72+
73+
``` javascript
74+
import config from 'app/config-APP_TARGET';
75+
console.log(config.title);
76+
```
77+
78+
And now you just get the right config imported depending on which target you're building for:
79+
80+
``` shell
81+
webpack --env.APP_TARGET VERSION_A
82+
=> 'I am version A'
83+
84+
webpack --env.APP_TARGET VERSION_B
85+
=> 'I am version B'
86+
87+
```

content/pluginsapi/tapable.md

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,39 @@ contributors:
77
- e-cloud
88
---
99

10-
[Tapable](https://github.com/webpack/tapable) is small library that allows you to add and apply plugins to a javascript module.
11-
It can be inherited or mixed in to other modules. It is similar to NodeJS's `EventEmitter` class, focusing on custom event emission and manipulation.
12-
However, in addition to this, `Tapable` allows you to have access to the "emittee" or "producer" of the event through callbacks arguments.
10+
[Tapable](https://github.com/webpack/tapable)是一个小型库,能够让我们为javascript模块添加并应用插件。
11+
它可以被其它模块继承或混合。它类似于NodeJS的 `EventEmitter` 类,专注于自定义事件的发射和操作。
12+
除此之外, `Tapable` 允许你通过回调函数的参数访问事件的生产者。
1313

14-
`Tapable` has four groups of member functions:
14+
`Tapable` 有四组成员函数:
1515

16-
* `plugin(name:string, handler:function)` - This allows a custom plugin to register into a **Tapable instance**'s event.
17-
This acts as the same as `on()` of `EventEmitter`, for registering a handler/listener to do something when the signal/event happens.
16+
* `plugin(name:string, handler:function)` - 这个方法允许给**Tapable实例**事件注册一个自定义插件。
17+
这个操作类似于 `EventEmitter``on()`, 注册一个处理函数/监听器到某个信号/事件发生时执行。
1818

19-
* `apply(…pluginInstances: (AnyPlugin|function)[])` - `AnyPlugin` should be subclass of [AbstractPlugin](https://github.com/webpack/webpack/blob/master/lib/AbstractPlugin.js), or a class (or object, rare case) has an `apply` method, or just a function with some registration code inside.
20-
This method is just to **apply** plugins' definition, so that the real event listeners can be registered into the **Tapable instance**'s registry.
19+
* `apply(…pluginInstances: (AnyPlugin|function)[])` - `AnyPlugin` [AbstractPlugin](https://github.com/webpack/webpack/blob/master/lib/AbstractPlugin.js)的子类, 或者是一个有 `apply` 方法的类(少数情况下是个对象),或者只是一个有注册代码的函数。
20+
这个方法只是 **apply** 插件的定义,所以正真的事件监听器会被注册到**Tapable实例**的注册表。
2121

22-
* `applyPlugins*(name:string, …)` - The **Tapable instance** can apply all the plugins under a particular hash using these functions.
23-
These group of method act like `emit()` of `EventEmitter`, to control the event emission meticulously with various strategy for various use cases.
22+
* `applyPlugins*(name:string, …)` - **Tapable instance** ????
23+
这些方法执行类似于 `EventEmitter``emit()`, 可以针对不同的使用情况采用不同的策略控制事件发射。
2424

25-
* `mixin(pt: Object)` - a simple method to extend `Tapable`'s prototype as a mixin rather than inheritance.
25+
* `mixin(pt: Object)` - 一个简单的方法能够以混合的方式扩展 `Tapable` 的原型,而非继承。
2626

27-
The different `applyPlugins*` methods cover the following use cases:
27+
不同的 `applyPlugins*` 方法对应以下使用情况:
2828

29-
* Plugins can run serially
29+
* 串行执行插件
3030

31-
* Plugins can run in parallel
31+
* 并行执行插件
3232

33-
* Plugins can run one after the other but taking input from the previous plugin (waterfall)
33+
* 插件一个接一个的执行,并且每个插件接收上一个插件的返回值(瀑布)
3434

35-
* Plugins can run asynchronously
35+
* 异步执行插件
3636

37-
* Quit runing plugins on bail: that is once one plugin returns non-`undefined`, jump out of the run flow and return *the return of that plugin*. This sounds like `once()` of `EventEmitter` but is totally different.
37+
* 保护模式终止插件执行: 一旦某个插件返回 non-`undefined` ,会退出运行流程并返回 *这个插件的返回值*。这看起来像 `EventEmitter``once()`,但他们是完全不同的。
3838

39-
## Example
40-
One of webpack's **Tapable instances**, [Compiler](./compiler), is responsible for compiling the webpack configuration object and returning a [Compilation](./compilation) instance. When the Compilation instance runs, it creates the required bundles.
39+
## 示例
40+
webpack中有个Tapable实例 [Compiler](./compiler), 它的作用是编译webpack的配置对象,并返回[Compilation](./compilation)实例。当Compilation实例运行时,它会创建所需的包。
4141

42-
See below is a simplified version of how this looks using `Tapable`.
42+
下面是一个使用 `Tapable` 的小例子。
4343

4444
**node_modules/webpack/lib/Compiler.js**
4545

@@ -51,7 +51,7 @@ function Compiler() {
5151
Compiler.prototype = Object.create(Tapable.prototype);
5252
```
5353

54-
Now to write a plugin on the compiler,
54+
接着写一个编译器的插件
5555

5656
**my-custom-plugin.js**
5757

@@ -62,7 +62,7 @@ CustomPlugin.prototype.apply = function(compiler) {
6262
}
6363
```
6464

65-
The compiler executes the plugin at the appropriate point in its lifecycle by
65+
这个编译器会依下面的代码在合适的生命周期点执行插件
6666

6767
**node_modules/webpack/lib/Compiler.js**
6868

@@ -72,4 +72,4 @@ this.apply*("emit",options) // will fetch all plugins under 'emit' name and run
7272

7373
***
7474

75-
> 原文:https://webpack.js.org/pluginsapi/tapable/
75+
> 原文:https://webpack.js.org/pluginsapi/tapable/

0 commit comments

Comments
 (0)