Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(en): merge webpack.js.org/master into webpack.js.org/cn @ f1c1cd3c #1415

Closed
wants to merge 9 commits into from
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
"directory-tree": "^3.0.1",
"directory-tree-webpack-plugin": "^1.0.3",
"duplexer": "^0.1.1",
"eslint": "^8.5.0",
"eslint": "^8.6.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-cypress": "^2.12.1",
"eslint-plugin-mdx": "^1.16.0",
Expand All @@ -105,8 +105,8 @@
"http-server": "^14.0.0",
"husky": "^7.0.4",
"hyperlink": "^5.0.3",
"jest": "^27.4.5",
"lint-staged": "^12.1.4",
"jest": "^27.4.7",
"lint-staged": "^12.1.5",
"lodash": "^4.17.21",
"markdownlint": "^0.25.0",
"markdownlint-cli": "^0.30.0",
Expand Down Expand Up @@ -138,7 +138,7 @@
"start-server-and-test": "^1.14.0",
"static-site-generator-webpack-plugin": "^3.4.1",
"style-loader": "^3.3.1",
"tailwindcss": "^3.0.8",
"tailwindcss": "^3.0.10",
"tap-spot": "^1.1.1",
"textlint": "^11.8.2",
"textlint-rule-heading": "^1.0.10",
Expand All @@ -158,7 +158,7 @@
"react-dom": "^17.0.2",
"react-helmet-async": "^1.2.2",
"react-router-dom": "^6.2.1",
"react-spring": "^9.3.3",
"react-spring": "^9.4.0",
"react-tiny-popover": "5",
"react-use": "^17.3.2",
"react-visibility-sensor": "^5.0.2",
Expand Down
24 changes: 24 additions & 0 deletions src/content/concepts/entry-points.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ contributors:
- chenxsan
- adyjs
- anshumanv
<<<<<<< HEAD
translators:
- QC-L
- jacob-lcs
- dear-lizhihua
- hanhan9449
=======
- ritikbanger
>>>>>>> f1c1cd3ccd29ed18159fb6397b97cd83b2c3987d
---

正如我们在 [起步](/guides/getting-started/#using-a-configuration) 中提到的,在 webpack 配置中有多种方式定义 `entry` 属性。除了解释为什么它可能非常有用,我们还将向你展示**如何去**配置 `entry` 属性。
Expand Down Expand Up @@ -57,7 +61,11 @@ module.exports = {
};
```

<<<<<<< HEAD
当你希望通过一个入口(例如一个库)为应用程序或工具快速设置 webpack 配置时,单一入口的语法方式是不错的选择。然而,使用这种语法方式来扩展或调整配置的灵活性不大。
=======
Single Entry Syntax is a great choice when you are looking to quickly set up a webpack configuration for an application or tool with one entry point (i.e. a library). However, there is not much flexibility in extending or scaling your configuration with this syntax.
>>>>>>> f1c1cd3ccd29ed18159fb6397b97cd83b2c3987d

## 对象语法 $#object-syntax$

Expand All @@ -82,15 +90,23 @@ T> 当你通过插件生成入口时,你可以传递空对象 `{}` 给 `entry`

### 描述入口的对象 $#entry-description-object$

<<<<<<< HEAD
用于描述入口的对象。你可以使用如下属性:
=======
An object of entry point description. You can specify the following properties.
>>>>>>> f1c1cd3ccd29ed18159fb6397b97cd83b2c3987d

- `dependOn`: 当前入口所依赖的入口。它们必须在该入口被加载前被加载。
- `filename`: 指定要输出的文件名称。
- `import`: 启动时需加载的模块。
- `library`: 指定 library 选项,为当前 entry 构建一个 library。
- `runtime`: 运行时 chunk 的名字。如果设置了,就会创建一个新的运行时 chunk。在 webpack 5.43.0 之后可将其设为 `false` 以避免一个新的运行时 chunk。

<<<<<<< HEAD
- `publicPath`: 当该入口的输出文件在浏览器中被引用时,为它们指定一个公共 URL 地址。请查看 [output.publicPath](/configuration/output/#outputpublicpath)。
=======
- `publicPath`: Specify a public URL address for the output files of this entry when they are referenced in a browser. Also, see [output.publicPath](/configuration/output/#outputpublicpath).
>>>>>>> f1c1cd3ccd29ed18159fb6397b97cd83b2c3987d

**webpack.config.js**

Expand Down Expand Up @@ -193,11 +209,19 @@ module.exports = {

**这是什么?** 这是告诉 webpack 我们想要配置 2 个单独的入口点(例如上面的示例)。

<<<<<<< HEAD
**为什么?** 这样你就可以在 `vendor.js` 中存入未做修改的必要 library 或文件(例如 Bootstrap, jQuery, 图片等),然后将它们打包在一起成为单独的 chunk。内容哈希保持不变,这使浏览器可以独立地缓存它们,从而减少了加载时间。
=======
**Why?** With this, you can import required libraries or files that aren't modified (e.g. Bootstrap, jQuery, images, etc) inside `vendor.js` and they will be bundled together into their own chunk. Content hash remains the same, which allows the browser to cache them separately thereby reducing load time.
>>>>>>> f1c1cd3ccd29ed18159fb6397b97cd83b2c3987d

T> 在 webpack < 4 的版本中,通常将 vendor 作为一个单独的入口起点添加到 entry 选项中,以将其编译为一个单独的文件(与 `CommonsChunkPlugin` 结合使用)。<br /><br /> 而在 webpack 4 中不鼓励这样做。而是使用 [`optimization.splitChunks`](/configuration/optimization/#optimizationsplitchunks) 选项,将 vendor 和 app(应用程序) 模块分开,并为其创建一个单独的文件。**不要** 为 vendor 或其他不是执行起点创建 entry。

<<<<<<< HEAD
### 多页面应用程序 $#multi-page-application$
=======
### Multi-Page Application
>>>>>>> f1c1cd3ccd29ed18159fb6397b97cd83b2c3987d

**webpack.config.js**

Expand Down
15 changes: 15 additions & 0 deletions src/content/migrate/5.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ contributors:
- chenxsan
- jamesgeorge007
- getsnoopy
<<<<<<< HEAD
translators:
- lcxfs1991
- QC-L
=======
- yevhen-logosha
>>>>>>> f1c1cd3ccd29ed18159fb6397b97cd83b2c3987d
---

本指南目标是帮助你在使用 webpack 的时候直接迁移到 webpack 5。如果你使用运行 webpack 更底层的工具,请
Expand All @@ -35,7 +39,12 @@ Webpack 5 对 Node.js 的版本要求至少是 10.13.0 (LTS),因此,如果

3. 升级所有使用到的 plugin 和 loader 为最新的可用版本。

<<<<<<< HEAD
部分 plugin 和 loader 可能会有一个 beta 版本,必须使用它们才能与 webpack 5 兼容。
=======
Some Plugins and Loaders might have a beta version that has to be used in order to be compatible with webpack 5.
Make sure to read release notes of each individual plugin/loader when upgrading it, since latest version might only support webpack 5 and will fail in v4. In such case, it's recommended to update to the latest version that supports webpack 4.
>>>>>>> f1c1cd3ccd29ed18159fb6397b97cd83b2c3987d

### 确保你的构建没有错误或警告 $#make-sure-your-build-has-no-errors-or-warnings$

Expand Down Expand Up @@ -96,7 +105,13 @@ T> webpack 5 从配置中移除了这些选项,并始终赋值 `false`。

- Yarn: `yarn add webpack@latest`

<<<<<<< HEAD
#### 清理配置 $#clean-up-configuration$
=======
If you were not able to upgrade some plugins/loaders to the latest in Upgrade webpack 4 and its plugins/loaders step, don't forget to upgrade them now.

### Clean up configuration
>>>>>>> f1c1cd3ccd29ed18159fb6397b97cd83b2c3987d

- 请考虑将 `optimization.moduleIds` 和 `optimization.chunkIds` 从你 webpack 配置中移除。使用默认值会更合适,因为它们会在 [`production 模式`](/configuration/mode/#mode-production) 下支持长效缓存且可以在 [`development` 模式](/configuration/mode/#mode-development)下进行调试。
- 当 webpack 配置中使用了 `[hash]` 占位符时,请考虑将它改为 `[contenthash]`。效果一致,但事实证明会更为有效。
Expand Down
Loading