Skip to content

Commit 916a942

Browse files
committed
Merge branch 'master' into cn
# Conflicts: # antwar.config.js # src/components/Navigation/Links.json # src/content/api/module-methods.md # src/content/concepts/index.md # src/content/concepts/mode.md # src/content/configuration/dev-server.md # src/content/configuration/output.md # src/content/guides/asset-management.md # src/content/guides/code-splitting.md # src/content/guides/getting-started.md # src/content/guides/production.md # src/content/migrate/3.md # src/content/plugins/index.md # src/scripts/fetch.sh
2 parents 4bb0c54 + 2632008 commit 916a942

22 files changed

+344
-231
lines changed

antwar.bootstrap.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ process.env.BABEL_ENV = environment;
77

88
antwar[environment]({
99
environment,
10-
configurationPaths: {
11-
antwar: require.resolve("./antwar.config.js"),
12-
webpack: require.resolve("./webpack.config.js"),
13-
},
10+
configurationPaths: {
11+
antwar: require.resolve("./antwar.config.js"),
12+
webpack: require.resolve("./webpack.config.js"),
13+
},
1414
}).then(() => {
15-
if (environment !== "build") {
16-
console.log("Surf to localhost:3000");
17-
}
15+
if (environment !== "build") {
16+
console.log("Surf to localhost:3000");
17+
}
1818
}).catch((err) => {
1919
console.error(err);
2020

antwar.config.js

+27-37
Original file line numberDiff line numberDiff line change
@@ -12,81 +12,71 @@ module.exports = () => ({
1212
layout: () => require('./src/components/Site/Site.jsx').default,
1313
paths: {
1414
'/': {
15-
title: 'Home',
15+
title: '首页',
1616
layout: () => require('./src/components/Page/Page.jsx').default,
1717
content: () => require.context('./loaders/page-loader!./src/content', false, /^\.\/.*\.md$/),
18-
index: () => require('./src/components/Splash/Splash.jsx').default,
19-
redirects: {
20-
'support': '/contribute',
21-
'writers-guide': '/contribute/writers-guide'
22-
}
18+
index: () => require('./src/components/Splash/Splash.jsx').default
2319
},
2420
concepts: {
2521
title: '概念',
26-
url: ({sectionName, fileName}) => `/${sectionName}/${fileName}/`,
22+
url: ({ sectionName, fileName }) => `/${sectionName}/${fileName}/`,
2723
layout: () => require('./src/components/Page/Page.jsx').default,
28-
content: () => require.context('./loaders/page-loader!./src/content/concepts', false, /^\.\/.*\.md$/),
24+
content: () => require.context('./loaders/page-loader!./src/content/concepts', false, /^\.\/.*\.md$/)
2925
},
3026
configuration: {
3127
title: '配置',
32-
url: ({sectionName, fileName}) => `/${sectionName}/${fileName}/`,
28+
url: ({ sectionName, fileName }) => `/${sectionName}/${fileName}/`,
3329
layout: () => require('./src/components/Page/Page.jsx').default,
34-
content: () => require.context('./loaders/page-loader!./src/content/configuration', false, /^\.\/.*\.md$/),
30+
content: () => require.context('./loaders/page-loader!./src/content/configuration', false, /^\.\/.*\.md$/)
3531
},
3632
api: {
3733
title: 'API',
38-
url: ({sectionName, fileName}) => `/${sectionName}/${fileName}/`,
34+
url: ({ sectionName, fileName }) => `/${sectionName}/${fileName}/`,
3935
layout: () => require('./src/components/Page/Page.jsx').default,
40-
content: () => require.context('./loaders/page-loader!./src/content/api', false, /^\.\/.*\.md$/),
41-
redirects: {
42-
'passing-a-config': 'configuration-types',
43-
},
36+
content: () => require.context('./loaders/page-loader!./src/content/api', false, /^\.\/.*\.md$/)
4437
},
4538
guides: {
4639
title: '指南',
47-
url: ({sectionName, fileName}) => `/${sectionName}/${fileName}/`,
40+
url: ({ sectionName, fileName }) => `/${sectionName}/${fileName}/`,
4841
layout: () => require('./src/components/Page/Page.jsx').default,
49-
content: () => require.context('./loaders/page-loader!./src/content/guides', false, /^\.\/.*\.md$/),
50-
redirects: {
51-
'code-splitting-import': '/guides/code-splitting',
52-
'code-splitting-require': '/guides/code-splitting',
53-
'code-splitting-async': '/guides/code-splitting',
54-
'code-splitting-css': '/guides/code-splitting',
55-
'code-splitting-libraries': '/guides/code-splitting',
56-
'why-webpack': '/comparison',
57-
'production-build': '/guides/production',
58-
},
42+
content: () => require.context('./loaders/page-loader!./src/content/guides', false, /^\.\/.*\.md$/)
5943
},
6044
plugins: {
6145
title: '插件',
62-
url: ({sectionName, fileName}) => `/${sectionName}/${fileName}/`,
46+
url: ({ sectionName, fileName }) => `/${sectionName}/${fileName}/`,
6347
layout: () => require('./src/components/Page/Page.jsx').default,
6448
content: () => {
6549
return combineContexts(
6650
require.context('./loaders/page-loader!./src/content/plugins', false, /^\.\/.*\.md$/),
67-
require.context('./loaders/page-loader!./generated/plugins', false, /^\.\/.*\.md$/),
68-
)
69-
},
51+
require.context('./loaders/page-loader!./generated/plugins', false, /^\.\/.*\.md$/)
52+
);
53+
}
7054
},
7155
loaders: {
7256
title: 'loaders',
73-
url: ({sectionName, fileName}) => `/${sectionName}/${fileName}/`,
57+
url: ({ sectionName, fileName }) => `/${sectionName}/${fileName}/`,
7458
layout: () => require('./src/components/Page/Page.jsx').default,
7559
content: () => {
7660
return combineContexts(
7761
require.context('./loaders/page-loader!./src/content/loaders', false, /^\.\/.*\.md$/),
78-
require.context('./loaders/page-loader!./generated/loaders', false, /^\.\/.*\.md$/),
79-
)
80-
},
62+
require.context('./loaders/page-loader!./generated/loaders', false, /^\.\/.*\.md$/)
63+
);
64+
}
8165
},
8266
contribute: {
8367
title: '贡献',
84-
url: ({sectionName, fileName}) => `/${sectionName}/${fileName}/`,
68+
url: ({ sectionName, fileName }) => `/${sectionName}/${fileName}/`,
69+
layout: () => require('./src/components/Page/Page.jsx').default,
70+
content: () => require.context('./loaders/page-loader!./src/content/contribute', false, /^\.\/.*\.md$/)
71+
},
72+
migrate: {
73+
title: '迁移',
74+
url: ({ sectionName, fileName }) => `/${sectionName}/${fileName}/`,
8575
layout: () => require('./src/components/Page/Page.jsx').default,
86-
content: () => require.context('./loaders/page-loader!./src/content/contribute', false, /^\.\/.*\.md$/),
76+
content: () => require.context('./loaders/page-loader!./src/content/migrate', false, /^\.\/.*\.md$/)
8777
},
8878
vote: () => require('./src/components/Vote/Vote.jsx').default,
8979
organization: () => require('./src/components/Organization/Organization.jsx').default,
90-
'starter-kits': () => require('./src/components/StarterKits/StarterKits.jsx').default,
80+
'starter-kits': () => require('./src/components/StarterKits/StarterKits.jsx').default
9181
}
9282
});

src/components/Navigation/Links.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
{ "title": "API", "url": "api" },
99
{ "title": "指南", "url": "guides" },
1010
{ "title": "loaders", "url": "loaders" },
11-
{ "title": "插件", "url": "plugins" }
11+
{ "title": "插件", "url": "plugins" },
12+
{ "title": "迁移", "url": "migrate" }
1213
]
1314
},
1415
{

src/components/Support/Support.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export default class Support extends React.Component {
104104
{<img
105105
className={ `support__${rank}-avatar` }
106106
src={ supporter.avatar || SmallIcon }
107-
alt={ supporter.name || supporter.slug ? `${supporter.name || supporter.slug}'s avatar` : 'avatar' }
107+
alt={ supporter.name || supporter.slug ? `${supporter.name || supporter.slug}'s avatar` : 'avatar' }
108108
onError={ this._handleImgError } />}
109109
{ rank === 'backer' ? <figure className="support__outline" /> : null }
110110
</a>
@@ -119,7 +119,7 @@ export default class Support extends React.Component {
119119
</div>
120120
);
121121
}
122-
122+
123123
/**
124124
* Handle images that aren't found
125125
*

src/content/api/module-methods.md

+17-1
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,21 @@ W> import() 特性依赖于内置的 [`Promise`](https://developer.mozilla.org/e
7373
`import` 规范不允许控制模块的名称或其他属性,因为 "chunks" 只是 webpack 中的一个概念。幸运的是,webpack 中可以通过注释接收一些特殊的参数,而无须破坏规定:
7474

7575
``` js
76+
// 单个目标
7677
import(
7778
/* webpackChunkName: "my-chunk-name" */
7879
/* webpackMode: "lazy" */
7980
'module'
8081
);
82+
83+
// 多个可能目标
84+
import(
85+
/* webpackInclude: /\.json$/ */
86+
/* webpackExclude: /\.noimport\.json$/ */
87+
/* webpackChunkName: "my-chunk-name" */
88+
/* webpackMode: "lazy" */
89+
`./locale/${language}`
90+
);
8191
```
8292

8393
`webpackChunkName`:新 chunk 的名称。从 webpack 2.6.0 开始,`[index]` and `[request]` 占位符,分别支持赋予一个递增的数字和实际解析的文件名。
@@ -91,9 +101,15 @@ import(
91101

92102
T> 请注意,这两个选项可以组合起来使用,如 `/* webpackMode: "lazy-once", webpackChunkName: "all-i18n-data" */`,这会按没有花括号的 JSON5 对象去解析。
93103

104+
`webpackInclude`:在导入解析(import resolution)过程中,用于匹配的正则表达式,只有匹配到的模块__才会被打包__
105+
106+
`webpackExclude`:在导入解析(import resolution)过程中,用于匹配的正则表达式,所有匹配到的模块__都不会被打包__
107+
108+
T> 注意,`webpackInclude``webpackExclude` 选项不会影响到前缀,例如:`./locale`
109+
94110
W> 完全动态的语句(如 `import(foo)`),因为 webpack 至少需要一些文件的路径信息,而 `foo` 可能是系统或项目中任何文件的任何路径,因此 `foo` 将会解析失败。`import()` 必须至少包含模块位于何处的路径信息,所以打包应当限制在一个指定目录或一组文件中。
95111

96-
W> 调用 `import()` 时,包含在其中的动态表达式 request,会潜在的请求的每个模块。例如,``import(`./locale/${language}.json`)`` 会导致 `./locale` 目录下的每个 `.json` 文件,都被打包到新的 chunk 中。在运行时,当计算出变量 `language` 时,任何文件(如 `english.json``german.json`)都可能会被用到。
112+
W> 调用 `import()` 时,包含在其中的动态表达式 request,会潜在的请求的每个模块。例如,``import(`./locale/${language}.json`)`` 会导致 `./locale` 目录下的每个 `.json` 文件,都被打包到新的 chunk 中。在运行时,当计算出变量 `language` 时,任何文件(如 `english.json``german.json`)都可能会被用到。 Using the `webpackInclude` and `webpackExclude` options allows us to add regex patterns that reduce the files that webpack will bundle for this import.
97113

98114
W> 在 webpack 中使用 `System.import` [不符合提案规范](https://github.com/webpack/webpack/issues/2163),所以在[2.1.0-beta.28](https://github.com/webpack/webpack/releases/tag/v2.1.0-beta.28) 后被弃用,并且建议使用 `import()`
99115

src/content/concepts/index.md

+24-28
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@ contributors:
1010
- TheDutchCoder
1111
- adambraimbridge
1212
- EugeneHlushko
13+
- jeremenichelli
1314
---
1415

15-
本质上,*webpack* 是一个现代 JavaScript 应用程序的_静态模块打包器(module bundler)_ webpack 处理应用程序时,它会递归地构建一个_依赖关系图(dependency graph)_其中包含应用程序需要的每个模块,然后将所有这些模块打包成一个或多个 _bundle_
16+
本质上,**webpack** 是一个现代 JavaScript 应用程序的_静态模块打包器(static module bundler)_ webpack 处理应用程序时,它会在内部创建一个_依赖图(dependency graph)_用于映射到项目需要的每个模块,然后将所有这些依赖生成到一个或多个_bundle_
1617

1718
T> 可以从[这里](/concepts/modules)了解更多关于 JavaScript 模块和 webpack 模块的信息。
1819

19-
从 webpack v4.0.0 开始,可以不用引入一个配置文件。然而,webpack 仍然还是[高度可配置的](/configuration)。在开始前你需要先理解四个**核心概念**
20+
从 webpack v4 开始,可以不用通过**引入一个配置文件**打包项目。然而,webpack 仍然还是 [高度可配置的](/configuration),并且能够很好的满足需求。
21+
22+
在开始前你需要先理解它的**核心概念**
2023

2124
- 入口(entry)
2225
- 输出(output)
@@ -28,13 +31,9 @@ T> 可以从[这里](/concepts/modules)了解更多关于 JavaScript 模块和 w
2831

2932
## 入口(entry)
3033

31-
**入口起点(entry point)**指示 webpack 应该使用哪个模块,来作为构建其内部*依赖图*的开始。进入入口起点后,webpack 会找出有哪些模块和库是入口起点(直接和间接)依赖的。
32-
33-
每个依赖项随即被处理,最后输出到称之为 *bundles* 的文件中,我们将在下一章节详细讨论这个过程。
34+
**入口起点(entry point)**指示 webpack 应该使用哪个模块,来作为构建其内部*依赖图*的开始,webpack 会找出有哪些模块和 library 是入口起点(直接和间接)依赖的。
3435

35-
可以通过在 [webpack 配置](/configuration)中配置 `entry` 属性,来指定一个入口起点(或多个入口起点)。默认值为 `./src`
36-
37-
接下来我们看一个 `entry` 配置的最简单例子:
36+
默认值是 `./src/index.js`,然而,可以通过在 [webpack 配置](/configuration)中配置 **entry** 属性,来指定一个不同的入口起点(或者也可以指定多个入口起点)。
3837

3938
__webpack.config.js__
4039

@@ -44,12 +43,14 @@ module.exports = {
4443
};
4544
```
4645

47-
T> 根据应用程序的特定需求,可以以多种方式配置 `entry` 属性。从[入口起点](/concepts/entry-points)章节可以了解更多信息。
46+
T> [入口起点](/concepts/entry-points) 章节可以了解更多信息。
4847

4948

5049
## 出口(output)
5150

52-
**output** 属性告诉 webpack 在哪里输出它所创建的 *bundles*,以及如何命名这些文件,默认值为 `./dist`。基本上,整个应用程序结构,都会被编译到你指定的输出路径的文件夹中。你可以通过在配置中指定一个 `output` 字段,来配置这些处理过程:
51+
**output** 属性告诉 webpack 在哪里输出它所创建的 *bundles*,以及如何命名这些文件,主输出文件默认为 `./dist/bundle.js`,其他生成文件的默认输出目录是 `./dist`
52+
53+
你可以通过在配置中指定一个 `output` 字段,来配置这些处理过程:
5354

5455
__webpack.config.js__
5556

@@ -67,20 +68,16 @@ module.exports = {
6768

6869
在上面的示例中,我们通过 `output.filename``output.path` 属性,来告诉 webpack bundle 的名称,以及我们想要 bundle 生成(emit)到哪里。可能你想要了解在代码最上面导入的 path 模块是什么,它是一个 [Node.js 核心模块](https://nodejs.org/api/modules.html),用于操作文件路径。
6970

70-
T> 你可能会发现术语**生成(emitted 或 emit)**贯穿了我们整个文档和[插件 API](/api/plugins)。它是“生产(produced)”或“释放(discharged)”的特殊术语。
71-
72-
T> `output` 属性还有[更多可配置的特性](/configuration/output),如果你想要了解更多关于 `output` 属性的概念,你可以通过[阅读概念章节](/concepts/output)来了解更多。
71+
T> `output` 属性还有 [更多可配置的特性](/configuration/output),可以通过阅读 [输出章节](/concepts/output) 来了解更多关于它的概念。
7372

7473

7574
## loader
7675

77-
*loader* 让 webpack 能够去处理那些非 JavaScript 文件(webpack 自身只理解 JavaScript)。loader 可以将所有类型的文件转换为 webpack 能够处理的有效[模块](/concepts/modules),然后你就可以利用 webpack 的打包能力,对它们进行处理。
78-
79-
本质上,webpack loader 将所有类型的文件,转换为应用程序的依赖图(和最终的 bundle)可以直接引用的模块。
76+
作为开箱即用的自带特性,webpack 自身只支持 JavaScript。而 **loader** 能够让 webpack 处理那些非 JavaScript 文件,并且先将它们转换为有效 [模块](/concepts/modules),然后添加到依赖图中,这样就可以提供给应用程序使用。
8077

8178
W> 注意,loader 能够 `import` 导入任何类型的模块(例如 `.css` 文件),这是 webpack 特有的功能,其他打包程序或任务执行器的可能并不支持。我们认为这种语言扩展是有很必要的,因为这可以使开发人员创建出更准确的依赖关系图。
8279

83-
在更高层面,在 webpack 的配置中 __loader__ 有两个目标:
80+
在更高层面,在 webpack 的配置中 **loader** 有两个目标:
8481

8582
1. `test` 属性,用于标识出应该被对应的 loader 进行转换的某个或某些文件。
8683
2. `use` 属性,表示进行转换时,应该使用哪个 loader。
@@ -108,16 +105,16 @@ module.exports = config;
108105

109106
> “嘿,webpack 编译器,当你碰到「在 `require()`/`import` 语句中被解析为 '.txt' 的路径」时,在你对它打包之前,先**使用** `raw-loader` 转换一下。”
110107
111-
W> 重要的是要记得,**在 webpack 配置中定义 loader 时,要定义在 `module.rules` 中,而不是 `rules`**。然而,在定义错误时 webpack 会给出严重的警告。为了使你受益于此,如果没有按照正确方式去做,webpack 会“给出严重的警告”
108+
W> 重要的是要记得,在 webpack 配置中定义 loader 时,要定义在 `module.rules` 中,而不是 `rules`为了使你受益于此,如果没有按照正确方式去做,webpack 会给出警告。
112109

113-
loader 还有更多我们尚未提到的具体配置属性。
114-
115-
[了解更多!](/concepts/loaders)
110+
你可以在 [loader 章节](/concepts/loaders) 中,进一步深入了解对引入的 loader 做自定义设置。
116111

117112

118113
## 插件(plugins)
119114

120-
loader 被用于转换某些类型的模块,而插件则可以用于执行范围更广的任务。插件的范围包括,从打包优化和压缩,一直到重新定义环境中的变量。[插件接口](/api/plugins)功能极其强大,可以用来处理各种各样的任务。
115+
loader 被用于转换某些类型的模块,而插件则可以用于执行范围更广的任务,插件的范围包括,打包优化、资源管理和注入环境变量。
116+
117+
T> 通过查看 [插件接口](/api/plugins) 文档,来了解如何使用它扩展 webpack 功能。
121118

122119
想要使用一个插件,你只需要 `require()` 它,然后把它添加到 `plugins` 数组中。多数插件可以通过选项(option)自定义。你也可以在一个配置文件中因为不同目的而多次使用同一个插件,这时需要通过使用 `new` 操作符来创建它的一个实例。
123120

@@ -134,29 +131,28 @@ const config = {
134131
]
135132
},
136133
plugins: [
137-
new webpack.optimize.UglifyJsPlugin(),
138134
new HtmlWebpackPlugin({template: './src/index.html'})
139135
]
140136
};
141137

142138
module.exports = config;
143139
```
144140

145-
webpack 提供许多开箱可用的插件!查阅我们的[插件列表](/plugins)获取更多信息
141+
在上面的示例中,`html-webpack-plugin` 会为你的应用程序生成一个 html 文件,然后自动注入所有生成的 bundle
146142

147-
webpack 配置中使用插件是简单直接的,然而也有很多值得我们进一步探讨的用例
143+
T> webpack 提供许多开箱可用的插件!查阅我们的 [插件列表](/plugins) 获取更多信息
148144

149-
[了解更多!](/concepts/plugins)
145+
在 webpack 配置中使用插件是简单直接的,然而也有很多值得我们进一步探讨的用例,查看这里 [了解更多!](/concepts/plugins)
150146

151147

152148
## 模式
153149

154-
通过选择 `development``production` 之中的一个,来设置 `mode` 参数,你可以启用相应模式下的 webpack 内置的优化
150+
通过将 `mode` 参数设置为 `development`, `production` `none`,可以启用对应环境下 webpack 内置的优化。默认值为 `production`
155151

156152
```javascript
157153
module.exports = {
158154
mode: 'production'
159155
};
160156
```
161157

162-
[了解更多!](/concepts/mode)
158+
[模式配置](/concepts/mode) 中可以了解到每种模式都做了哪些优化。

src/content/concepts/mode.md

+15-1
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ module.exports = {
2626
webpack --mode=production
2727
```
2828

29-
支持以下字符串值
29+
如果不设置,webpack 会将 `production` 设为 `mode` 的默认值。mode 支持以下值
3030

3131
选项 | 描述
3232
--------------------- | -----------------------
3333
`development` | 会将 `process.env.NODE_ENV` 的值设为 `development`。启用 `NamedChunksPlugin``NamedModulesPlugin`
3434
`production` | 会将 `process.env.NODE_ENV` 的值设为 `production`。启用 `FlagDependencyUsagePlugin`, `FlagIncludedChunksPlugin`, `ModuleConcatenationPlugin`, `NoEmitOnErrorsPlugin`, `OccurrenceOrderPlugin`, `SideEffectsFlagPlugin``UglifyJsPlugin`.
35+
`none` | 不选用任何默认优化选项
3536

3637
T> 记住,只设置 `NODE_ENV`,则不会自动设置 `mode`
3738

@@ -66,3 +67,16 @@ module.exports = {
6667
- ]
6768
}
6869
```
70+
71+
72+
### mode: none
73+
74+
75+
```diff
76+
// webpack.custom.config.js
77+
module.exports = {
78+
+ mode: 'none',
79+
- plugins: [
80+
- ]
81+
}
82+
```

0 commit comments

Comments
 (0)