Skip to content

Commit a60e104

Browse files
92hackersQC-L
andauthored
docs(cn): translate src/content/loaders/html-loader.md (#833)
Co-authored-by: QiChang Li <[email protected]>
1 parent 5e7adbc commit a60e104

File tree

1 file changed

+85
-85
lines changed

1 file changed

+85
-85
lines changed

src/content/loaders/html-loader.md

Lines changed: 85 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ repo: https://github.com/webpack-contrib/html-loader
1616

1717

1818

19-
Exports HTML as string. HTML is minimized when the compiler demands.
19+
HTML 导出为字符串。当编译器需要时,将压缩 HTML 字符串。
2020

21-
## Getting Started {#getting-started}
21+
## 入门 {#getting-started}
2222

23-
To begin, you'll need to install `html-loader`:
23+
首先,你需要安装 `html-loader`
2424

2525
```console
2626
npm install --save-dev html-loader
2727
```
2828

29-
Then add the plugin to your `webpack` config. For example:
29+
然后将插件添加到你的 `webpack` 配置中。例如:
3030

3131
**file.js**
3232

@@ -49,42 +49,42 @@ module.exports = {
4949
};
5050
```
5151

52-
## Options {#options}
52+
## 选项 {#options}
5353

54-
| Name | Type | Default | Description |
55-
| :---------------------------------: | :-----------------: | :------------------------------------------: | :----------------------------------------------- |
56-
| **[`attributes`](#attributes)** | `{Boolean\|Object}` | `true` | Enables/Disables attributes handling |
57-
| **[`preprocessor`](#preprocessor)** | `{Function}` | `undefined` | Allows pre-processing of content before handling |
58-
| **[`minimize`](#minimize)** | `{Boolean\|Object}` | `true` in production mode, otherwise `false` | Tell `html-loader` to minimize HTML |
59-
| **[`esModule`](#esmodule)** | `{Boolean}` | `false` | Use ES modules syntax |
54+
| 名称 | 类型 | 默认 | 描述 |
55+
| :-: | :-: | :-: | :-- |
56+
| **[`attributes`](#attributes)** | `{Boolean|Object}` | `true` | 启用 / 禁用属性处理 |
57+
| **[`preprocessor`](#preprocessor)** | `{Function}` | `undefined` | 允许在处理之前对内容进行预处理 |
58+
| **[`minimize`](#minimize)** | `{Boolean|Object}` | 在生产环境下为 `true` ,否则为 `false` | 告诉 `html-loader` 压缩 HTML |
59+
| **[`esModule`](#esmodule)** | `{Boolean}` | `false` | 使用 ES 模块语法 |
6060

6161
### `attributes` {#attributes}
6262

63-
Type: `Boolean|Object`
64-
Default: `true`
63+
类型: `Boolean|Object`
64+
默认值: `true`
6565

66-
By default every loadable attributes (for example - `<img src="image.png">`) is imported (`const img = require('./image.png')` or `import img from "./image.png""`).
67-
You may need to specify loaders for images in your configuration (recommended `file-loader` or `url-loader`).
66+
默认情况下,每个可加载属性(例如 - `<img src="image.png">` )都将被导入( `const img = require ('./image.png')` `import img from "./image.png""` )。
67+
你可能需要为配置中的图片指定 loader(推荐使用 `file-loader` `url-loader` )。
6868

69-
Supported tags and attributes:
69+
支持的标签和属性:
7070

71-
- the `src` attribute of the `audio` tag
72-
- the `src` attribute of the `embed` tag
73-
- the `src` attribute of the `img` tag
74-
- the `srcset` attribute of the `img` tag
75-
- the `src` attribute of the `input` tag
76-
- the `href` attribute of the `link` tag (only for stylesheets)
77-
- the `data` attribute of the `object` tag
78-
- the `src` attribute of the `script` tag
79-
- the `src` attribute of the `source` tag
80-
- the `srcset` attribute of the `source` tag
81-
- the `src` attribute of the `track` tag
82-
- the `poster` attribute of the `video` tag
83-
- the `src` attribute of the `video` tag
71+
- `audio` 标签的 `src` 属性
72+
- `embed` 标签的 `src` 属性
73+
- `img` 标签的 `src` 属性
74+
- `img` 标签的 `srcset` 属性
75+
- `input` 标签的 `src` 属性
76+
- `link` 标记的 `href` 属性(仅适用于样式表)
77+
- `object` 标签的 `data` 属性
78+
- `script` 标签的 `src` 属性
79+
- `source` 标签的 `src` 属性
80+
- `source` 标签的 `srcset` 属性
81+
- `track` 标记的 `src` 属性
82+
- `video` 标签的 `poster` 属性
83+
- `video` 代码的 `src` 属性
8484

8585
#### `Boolean` {#boolean}
8686

87-
The `true` value enables processing of all default elements and attributes, the `false` disable processing of all attributes.
87+
当设置为 `true` 时,则启用所有默认元素和属性的处理,而 `false` 则禁用所有属性的处理。
8888

8989
**webpack.config.js**
9090

@@ -107,8 +107,8 @@ module.exports = {
107107

108108
#### `Object` {#object}
109109

110-
Allows you to specify which tags and attributes to process, filter them, filter urls and process sources starts with `/`.
111-
For example:
110+
你可以配置要处理的标签和属性,来过滤它们,过滤 URL 并处理以 `/` 开头的资源地址。
111+
例如:
112112

113113
**webpack.config.js**
114114

@@ -185,12 +185,12 @@ module.exports = {
185185

186186
#### `list` {#list}
187187

188-
Type: `Array`
189-
Default: https://github.com/webpack-contrib/html-loader#attributes
188+
类型:`Array`
189+
默认值: https://github.com/webpack-contrib/html-loader#attributes
190190

191-
Allows to setup which tags and attributes to process and how, and the ability to filter some of them.
191+
允许设置要处理的标签和属性以及处理方式,以及过滤其中一些标签和属性的能力。
192192

193-
For example:
193+
例如:
194194

195195
**webpack.config.js**
196196

@@ -271,11 +271,11 @@ module.exports = {
271271
};
272272
```
273273

274-
If the tag name is not specified it will process all the tags.
274+
如果未指定标签名称,它将处理所有标签。
275275

276-
> You can use your custom filter to specify html elements to be processed.
276+
> 你可以使用自定义过滤器指定要处理的 html 元素。
277277
278-
For example:
278+
例如:
279279

280280
**webpack.config.js**
281281

@@ -316,11 +316,11 @@ module.exports = {
316316

317317
#### `urlFilter` {#urlfilter}
318318

319-
Type: `Function`
320-
Default: `undefined`
319+
类型:`Function`
320+
默认值: `undefined`
321321

322-
Allow to filter urls. All filtered urls will not be resolved (left in the code as they were written).
323-
All non requestable sources (for example `<img src="javascript:void(0)">`) do not handle by default.
322+
允许配置要过滤的 url。所有过滤的 url 都参与解析(会保持原样)。
323+
默认情况下,所有非请求资源类型的值(例如 `<img src="javascript:void (0)">` )都不处理。
324324

325325
```js
326326
module.exports = {
@@ -352,11 +352,11 @@ module.exports = {
352352

353353
#### `root` {#root}
354354

355-
Type: `String`
356-
Default: `undefined`
355+
类型:`String`
356+
默认值: `undefined`
357357

358-
For urls that start with a `/`, the default behavior is to not translate them.
359-
If a `root` query parameter is set, however, it will be prepended to the url and then translated.
358+
对于 `/` 开头的 url,默认不进行转换。
359+
但是,如果设置了 `root` 查询参数,它将被放在 URL 之前进行转换。
360360

361361
**webpack.config.js**
362362

@@ -380,12 +380,12 @@ module.exports = {
380380

381381
### `preprocessor` {#preprocessor}
382382

383-
Type: `Function`
384-
Default: `undefined`
383+
类型:`Function`
384+
默认值:`undefined`
385385

386-
Allows pre-processing of content before handling.
386+
允许在处理之前对内容进行预处理。
387387

388-
> You should always return valid HTML
388+
> 你应该始终返回有效的 HTML
389389
390390
**file.hbs**
391391

@@ -398,7 +398,7 @@ Allows pre-processing of content before handling.
398398

399399
#### `Function` {#function}
400400

401-
You can set the `preprocessor` option as a `Function` instance.
401+
你可以将 `preprocessor` 选项设置为 `Function` 实例。
402402

403403
**webpack.config.js**
404404

@@ -435,9 +435,9 @@ module.exports = {
435435
};
436436
```
437437

438-
You can also set the `preprocessor` option as an asynchronous function instance.
438+
你还可以将 `preprocessor` 选项设置为异步函数实例。
439439

440-
For example:
440+
例如:
441441

442442
**webpack.config.js**
443443

@@ -476,14 +476,14 @@ module.exports = {
476476

477477
### `minimize` {#minimize}
478478

479-
Type: `Boolean|Object`
480-
Default: `true` in production mode, otherwise `false`
479+
类型:`Boolean|Object`
480+
默认值:在生产模式下为 `true` ,否则为 `false`
481481

482-
Tell `html-loader` to minimize HTML.
482+
告诉 `html-loader` 编译时需要压缩 HTML 字符串。
483483

484484
#### `Boolean` {#boolean}
485485

486-
The enabled rules for minimizing by default are the following ones:
486+
默认情况下,启用压缩的规则如下:
487487

488488
```js
489489
({
@@ -522,9 +522,9 @@ module.exports = {
522522

523523
**webpack.config.js**
524524

525-
See [html-minifier-terser](https://github.com/DanielRuf/html-minifier-terser)'s documentation for more information on the available options.
525+
关于可用选项的更多信息,请参阅 [html-minifier-terser](https://github.com/DanielRuf/html-minifier-terser) 文档。
526526

527-
The rules can be disabled using the following options in your `webpack.conf.js`
527+
可以在 `webpack.conf.js` 中使用以下选项来禁用规则
528528

529529
**webpack.config.js**
530530

@@ -549,13 +549,13 @@ module.exports = {
549549

550550
### `esModule` {#esmodule}
551551

552-
Type: `Boolean`
553-
Default: `false`
552+
类型:`Boolean`
553+
值默认值:`false`
554554

555-
By default, `html-loader` generates JS modules that use the CommonJS modules syntax.
556-
There are some cases in which using ES modules is beneficial, like in the case of [module concatenation](/plugins/module-concatenation-plugin/) and [tree shaking](/guides/tree-shaking/).
555+
默认情况下, `html-loader` 生成使用 CommonJS 模块语法的 JS 模块。
556+
在某些情况下,使用 ES 模块会更好,例如在进行[模块合并](/plugins/module-concatenation-plugin/)[tree shaking](/guides/tree-shaking/) 时。
557557

558-
You can enable a ES module syntax using:
558+
你可以使用以下方法启用 ES 模块语法:
559559

560560
**webpack.config.js**
561561

@@ -575,7 +575,7 @@ module.exports = {
575575
};
576576
```
577577

578-
## Examples {#examples}
578+
## 示例 {#examples}
579579

580580
### CDN {#cdn}
581581

@@ -627,9 +627,9 @@ require('html-loader?-attributes!./file.html');
627627
// => '<img src="image.jpg" data-src="image2x.png" >'
628628
```
629629

630-
> :warning: `-attributes` sets `attributes: false`.
630+
> warning `-attributes` 设置 `attributes: false`
631631
632-
### Process `script` and `link` tags {#process-script-and-link-tags}
632+
### 处理 `script` `link` 标签 {#process-script-and-link-tags}
633633

634634
**script.file.js**
635635

@@ -695,9 +695,9 @@ module.exports = {
695695
};
696696
```
697697

698-
### 'Root-relative' URLs {#root-relative-urls}
698+
### “相对根” 的 URL {#root-relative-urls}
699699

700-
With the same configuration as in the CDN example:
700+
CDN 示例中的配置相同:
701701

702702
**file.html**
703703

@@ -721,9 +721,9 @@ require('html-loader?{"attributes":{"root":"."}}!./file.html');
721721
// => '<img src="http://cdn.example.com/49eba9f/a992ca.jpg">'
722722
```
723723

724-
### Templating {#templating}
724+
### 模板 {#templating}
725725

726-
You can use any template system. Below is an example for [handlebars](https://handlebarsjs.com/).
726+
你可以使用任何模板系统。以下是 [handlebars](https://handlebarsjs.com/) 的示例。
727727

728728
**file.hbs**
729729

@@ -771,7 +771,7 @@ module.exports = {
771771

772772
### PostHTML {#posthtml}
773773

774-
You can use [PostHTML](https://github.com/posthtml/posthtml) without any additional loaders.
774+
你可以使用 [PostHTML](https://github.com/posthtml/posthtml) 而无需任何其他加载程序。
775775

776776
**file.html**
777777

@@ -812,20 +812,20 @@ module.exports = {
812812
};
813813
```
814814

815-
### Export into HTML files {#export-into-html-files}
815+
### 导出为 HTML 文件 {#export-into-html-files}
816816

817-
A very common scenario is exporting the HTML into their own _.html_ file, to
818-
serve them directly instead of injecting with javascript. This can be achieved
819-
with a combination of 3 loaders:
817+
一种非常常见的情况是将 HTML 导出到自己的 *.html* 文件中,
818+
以直接使用,而非注入到 javascript
819+
可以使用以下 3 种 loader 来实现:
820820

821821
- [file-loader](/loaders/file-loader/)
822822
- [extract-loader](https://github.com/peerigon/extract-loader)
823823
- html-loader
824824

825-
The html-loader will parse the URLs, require the images and everything you
826-
expect. The extract loader will parse the javascript back into a proper html
827-
file, ensuring images are required and point to proper path, and the file loader
828-
will write the _.html_ file for you. Example:
825+
html-loader 将解析 URL,同时引入图片以及你需要的所有内容。
826+
extract-loader 会将 javascript 解析为正确的 html 文件,
827+
然后确保图片被引入且路径正确,
828+
file-loader 会为你生成 *.html* 文件。例如:
829829

830830
**webpack.config.js**
831831

@@ -842,13 +842,13 @@ module.exports = {
842842
};
843843
```
844844

845-
## Contributing {#contributing}
845+
## 贡献 {#contributing}
846846

847-
Please take a moment to read our contributing guidelines if you haven't yet done so.
847+
如果你还没有阅读,请花一点时间阅读我们的贡献指南。
848848

849-
[CONTRIBUTING](https://github.com/webpack-contrib/html-loader/blob/master/.github/CONTRIBUTING.md)
849+
[贡献](https://github.com/webpack-contrib/html-loader/blob/master/.github/CONTRIBUTING.md)
850850

851-
## License {#license}
851+
## 许可证 {#license}
852852

853853
[MIT](https://github.com/webpack-contrib/html-loader/blob/master/LICENSE)
854854

0 commit comments

Comments
 (0)