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/guides/development.md
+44-44Lines changed: 44 additions & 44 deletions
Original file line number
Diff line number
Diff line change
@@ -5,109 +5,110 @@ contributors:
5
5
- SpaceK33z
6
6
---
7
7
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.
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.
**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:
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.
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.
We also want a nice progress bar while it's compiling. Let's run the command:
47
+
我们也希望在编译时有一个好看的进度条。运行以下命令:
47
48
48
49
```bash
49
50
webpack --progress --watch
50
51
```
51
52
52
-
Make a change in one of your files and hit save. You should see that it's recompiling.
53
+
在你的文件中做一点更改并且保存。你应该会看到 webpack 正在重新编译。
53
54
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`),你可以在输出的文件目录下运行它:
55
56
56
57
```bash
57
58
serve
58
59
```
59
60
60
-
After each compilation, you will need to manually refresh your browser to see the changes.
61
+
在每一次编译后,你需要手动刷新你的浏览器来查看更改。
61
62
62
63
### webpack-dev-server
63
64
64
-
webpack-dev-server provides you with a server and live reloading. This is easy to setup.
Start with installing`webpack-dev-server` from npm:
73
+
首先从 npm 安装`webpack-dev-server`:
73
74
74
75
```bash
75
76
npm install webpack-dev-server --save-dev
76
77
```
77
78
78
-
When it's done installing, you should be able to use `webpack-dev-server`like this:
79
+
安装完成之后,你应该可以使用 `webpack-dev-server`了,方式如下:
79
80
80
81
```bash
81
82
webpack-dev-server --open
82
83
```
83
84
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" }`.
The command above should automatically open your browser on `http://localhost:8080`.
87
+
上述命令应该自动在浏览器中打开 `http://localhost:8080`。
87
88
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-).
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).
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.
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).
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.
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.
0 commit comments