Skip to content

Commit 920ce8c

Browse files
committed
翻译 guides/development
1 parent c0d31e6 commit 920ce8c

File tree

1 file changed

+44
-44
lines changed

1 file changed

+44
-44
lines changed

content/guides/development.md

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,109 +5,110 @@ contributors:
55
- SpaceK33z
66
---
77

8-
On this page we'll explain how to get started with developing and how to choose one of three tools to develop. It is assumed you already have a webpack configuration file.
8+
在这一章节,我们将会解释如何开始开发并且如何从三种开发工具中进行选择。这里假设你已经有了一个 webpack 配置文件。
99

10-
W> Never use any of these tools in production. Ever.
10+
W> 永远不要在生产环境中使用这些工具,永远不要。
1111

12-
## Adjusting Your Text Editor
12+
## 调整你的文本编辑器
1313

14-
Some text editors have a "safe write" feature and enable this by default. As a result, saving a file will not always result in a recompile.
14+
一些文本编辑器有“safe write”(安全写入)功能,并且默认启用。因此,保存文件后并不总是会导致 webpack 重新编译。
1515

16-
Each editor has a different way of disabling this. For the most common ones:
16+
每个编辑器都有不同的方式来禁用这一功能,以下是一些最常见的:
1717

18-
* **Sublime Text 3** - Add `"atomic_save": false` to your user preferences.
19-
* **IntelliJ** - use search in the preferences to find "safe write" and disable it.
20-
* **Vim** - add `:set backupcopy=yes` in your settings.
21-
* **WebStorm** - uncheck `Use "safe write"` in Preferences > Appearance & Behavior > System Settings
18+
* **Sublime Text 3** - 在用户设置(preference)中增加 `"atomic_save": false`
19+
* **IntelliJ** - 在设置中查找 “safe write”并且禁用它。
20+
* **Vim** - 在设置中增加 `:set backupcopy=yes`
21+
* **WebStorm** - Preferences > Appearance & Behavior > System Settings 中取消选中 `Use "safe write"`
2222

2323
## Source Maps
2424

25-
When a JavaScript exception occurs, you'll often want to know what file and line is generating this error. Since webpack outputs files into one or more bundles, it can be inconvenient to trace the file.
25+
JavaScript 异常抛出时,你会想知道这个错误发生在哪个文件的哪一行。然而因为 webpack 将文件输出为一个或多个 bundle,所以追踪这一错误会很不方便。
2626

27-
**Source maps** intend to fix this problem. There are a lot of [different options](/configuration/devtool) - each with their own advantages and disadvantages. To get started, we'll use this one:
27+
**Source maps** 试图解决这一问题。它有很多[不同的选项](/configuration/devtool) - 每一个都有自己的优缺点。首先,我们使用这一个:
2828

2929
```js
3030
devtool: "cheap-eval-source-map"
3131
```
3232

33-
## Choosing a Tool
33+
## 选择一个工具
3434

35-
webpack can be used with **watch mode**. In this mode webpack will watch your files, and recompile when they change.
36-
**webpack-dev-server** provides an easy to use development server with fast live reloading. If you already have a development server and want full flexibility, **webpack-dev-middleware** can be used as middleware.
35+
webpack 可以在 **watch mode**(监视模式)下使用。在这种模式下,webpack 将监视您的文件,并在更改时重新编译。
36+
**webpack-dev-server** 提供了一个易于部署的开发服务器,具有快速的实时重载(live reloading)功能。
37+
如果你已经有一个开发服务器并且需要完全的灵活性,可以使用 **webpack-dev-middleware** 作为中间件。
3738

38-
webpack-dev-server and webpack-dev-middleware use in-memory compilation, meaning that the bundle will not be saved to disk. This makes compiling faster and results in less mess on your file system.
39+
webapck-dev-server webpack-dev-middleware 使用内存编译,这意味着 bundle 不会被保存在硬盘上。这使得编译十分迅速,并导致你的文件系统更少麻烦。
3940

40-
In most cases **you'll want to use webpack-dev-server**, since it's the easiest to get started with and offers much functionality out-of-the-box.
41+
在大多数情况下**你会想要使用 webpack-dev-server**,因为这是最简单的开始的方式,并且提供了很多开箱即用的功能。
4142

42-
### webpack Watch Mode
43+
### webpack Watch Mode(监视模式)
4344

44-
webpack's watch mode watches files for changes. If any change is detected, it'll run the compilation again.
45+
webpackwatch mode 会监视文件的更改。如果检测到任何的更改,它都会再次执行编译。
4546

46-
We also want a nice progress bar while it's compiling. Let's run the command:
47+
我们也希望在编译时有一个好看的进度条。运行以下命令:
4748

4849
```bash
4950
webpack --progress --watch
5051
```
5152

52-
Make a change in one of your files and hit save. You should see that it's recompiling.
53+
在你的文件中做一点更改并且保存。你应该会看到 webpack 正在重新编译。
5354

54-
Watch mode makes no assumptions about a server, so you will need to provide your own. An easy server is [`serve`](https://github.com/tj/serve). After installing (`npm i serve -g`), you can execute it in the directory where the outputted files are:
55+
watch mode 对服务器没有预设,所以你需要自己提供一个。一个简易的服务器是 [`serve`](https://github.com/tj/serve)。安装之后(`npm i serve -g`),你可以在输出的文件目录下运行它:
5556

5657
```bash
5758
serve
5859
```
5960

60-
After each compilation, you will need to manually refresh your browser to see the changes.
61+
在每一次编译后,你需要手动刷新你的浏览器来查看更改。
6162

6263
### webpack-dev-server
6364

64-
webpack-dev-server provides you with a server and live reloading. This is easy to setup.
65+
webpack-dev-server 为你提供了一个服务器和实时重载(live reloading) 功能。这很容易设置。
6566

66-
To prepare, make sure you have a `index.html` file that points to your bundle. Assuming that `output.filename` is `bundle.js`:
67+
在开始前,确定你有一个 `index.html` 文件指向你的 bundle。假设 `output.filename` `bunlde.js`
6768

6869
```html
6970
<script src="/bundle.js"></script>
7071
```
7172

72-
Start with installing `webpack-dev-server` from npm:
73+
首先从 npm 安装 `webpack-dev-server`
7374

7475
```bash
7576
npm install webpack-dev-server --save-dev
7677
```
7778

78-
When it's done installing, you should be able to use `webpack-dev-server` like this:
79+
安装完成之后,你应该可以使用 `webpack-dev-server` 了,方式如下:
7980

8081
```bash
8182
webpack-dev-server --open
8283
```
8384

84-
T> If your console says it can't find the command, try running `node_modules/.bin/webpack-dev-server`. Optimally you would add the command to your `package.json`, like this: `"scripts": { "start": "webpack-dev-server" }`.
85+
T> 如果你的控制台说无法找到该命令,尝试运行 `node_modules/.bin/webpack-dev-server`。正常情况下你应该把该命令加在 `package.json` 中,例如:`"scripts": {"start": "webpack-dev-server"}`
8586

86-
The command above should automatically open your browser on `http://localhost:8080`.
87+
上述命令应该自动在浏览器中打开 `http://localhost:8080`
8788

88-
Make a change in one of your files and hit save. You should see that the console is recompiling. After that's done, the page should be refreshed. If nothing happens in the console, you may need to fiddle with [`watchOptions`](/configuration/dev-server#devserver-watchoptions-).
89+
在你的文件中做一点更改并且保存。你应该可以在控制台中看到正在编译。完成之后,页面应该会刷新。如果控制台中什么都没发生,你可能需要调整下 [`watchOptions`](/configuration/dev-server#devserver-watchoptions-)
8990

90-
Now you have live reloading working, you can take it even a step further: Hot Module Replacement. This is an interface that makes it possible to swap modules **without a page refresh**. Find out how to [configure HMR](/guides/hmr-react).
91+
现在你有了实时重载功能,你甚至可以更进一步:Hot Module Replacement(热模块替换)。这是一个接口,使得可以替换模块**而不需要刷新页面**。查看如何[配置 HMR](/guides/hmr-react)
9192

92-
By default **inline mode** is used. This mode injects the client - needed for live reloading and showing build errors - in your bundle. With inline mode you will get build errors and warnings in your DevTools console.
93+
默认情况下 webpack 会使用**inline mode**(内联模式)。这种模式在你的 bundle 中注入客户端(用来 live reloading 和展示构建错误)。Inline 模式下,你会在你的 DevTools 控制台中看到构建错误。
9394

94-
webpack-dev-server can do many more things such as proxying requests to your backend server. For more configuration options, see the [**devServer documentation**](/configuration/dev-server).
95+
webpack-dev-server 可以做很多事情,比如转发请求到你的后端服务器。更多配置项,请参阅 [**devServer documentation**](/configuration/dev-server)
9596

9697
### webpack-dev-middleware
9798

98-
webpack-dev-middleware works for connect-based middleware stacks. This can be useful if you already have a Node.js server or if you want to have full control over the server.
99+
webpack-dev-middleware 适用于基于链接的中间件环境(connect-based middleware stacks)。如果你已经有一个 Node.js 服务器或者你想要完全控制服务器,这将很实用。
99100

100-
The middleware will cause webpack to compile files in-memory. When a compilation is running, it will delay the request to a file until the compilation is done.
101+
这个中间件会导致 webpack 在内存中编译文件。当一个编译正在执行的时候,它会将对于文件的请求延迟,直到编译完成。
101102

102-
W> This is intended for advanced users. webpack-dev-server is much easier to use.
103+
W> 该中间件是为进阶用户使用的。对于一般用户,webpack-dev-server 更容易使用。
103104

104-
Start with installing the dependencies from npm:
105+
首先从 npm 上安装依赖:
105106

106107
```bash
107108
npm install express webpack-dev-middleware --save-dev
108109
```
109110

110-
After installing, you can use the middleware like this:
111+
安装完成后,可以按如下所示使用该中间件:
111112

112113
```js
113114
var express = require("express");
@@ -119,19 +120,19 @@ var app = express();
119120
var compiler = webpack(webpackConfig);
120121

121122
app.use(webpackDevMiddleware(compiler, {
122-
publicPath: "/" // Same as `output.publicPath` in most cases.
123+
publicPath: "/" // 大部分情况下和 `output.publicPath`相同
123124
}));
124125

125126
app.listen(3000, function () {
126127
console.log("Listening on port 3000!");
127128
});
128129
```
129130

130-
Depending on what you've used in `output.publicPath` and `output.filename`, your bundle should now be available on `http://localhost:3000/bundle.js`.
131+
根据你在 `output.publicPath` `output.filename` 中设置的内容,你的 bundle 现在应该在 `http://localhost:3000/bundle.js` 中可以看到了。
131132

132-
By default, **watch mode** is used. It's also possible to use **lazy mode**, which will only recompile on a request to the entry point.
133+
默认情况下会使用**watch mode**。也可以使用 **lazy mode**,这使得 webpack 只在对入口点进行请求时再进行重新编译。
133134

134-
To compile only on a request to the entry `bundle.js`:
135+
设置仅在对入口 `bundle.js` 请求时进行编译:
135136

136137
```js
137138
app.use(webpackDevMiddleware(compiler, {
@@ -140,10 +141,9 @@ app.use(webpackDevMiddleware(compiler, {
140141
}));
141142
```
142143

143-
There are many more options you can use. For all configuration options, see the [**devServer documentation**](/configuration/dev-server).
144+
还有许多其他的选项可以设置。所有的设置项请查阅 [**devServer 文档**](/configuration/dev-server)
144145

145-
146-
## References
146+
## 参考
147147

148148
* [SurviveJS - Automatic Browser Refresh](http://survivejs.com/webpack/developing-with-webpack/automatic-browser-refresh/)
149149

0 commit comments

Comments
 (0)