Skip to content

Commit 0f030ce

Browse files
Merge pull request webpack#125 from yuanlinssdut/cn
file-loader
2 parents 6990d55 + f7a7f07 commit 0f030ce

File tree

1 file changed

+28
-31
lines changed

1 file changed

+28
-31
lines changed

generated/loaders/file-loader.md

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,57 +3,54 @@ title: file-loader
33
source: https://raw.githubusercontent.com/webpack/file-loader/master/README.md
44
edit: https://github.com/webpack/file-loader/edit/master/README.md
55
---
6-
## Install
6+
## 安装
77

88
```bash
99
npm install --save-dev file-loader
1010
```
1111

12-
## Usage
12+
## 用法
1313

14-
By default the filename of the resulting file is the MD5 hash of the file's contents
15-
with the original extension of the required resource.
14+
默认情况下,生成的文件的文件名就是文件内容的 MD5 哈希值并会保留所引用资源的原始扩展名。
1615

1716
``` javascript
1817
var url = require("file-loader!./file.png");
19-
// => emits file.png as file in the output directory and returns the public url
20-
// => returns i. e. "/public-path/0dcbbaa701328a3c262cfd45869e351f.png"
18+
// => 输出 file.png 文件到输出目录并返回public url
19+
// => 即返回 "/public-path/0dcbbaa701328a3c262cfd45869e351f.png"
2120
```
2221

23-
By default a file is emitted, however this can be disabled if required (e.g. for server
24-
side packages).
22+
默认情况下,文件会被输出,不过如果需要的话,也可以不输出(比如使用了服务端的 packages)。
2523

2624
``` javascript
2725
var url = require("file-loader?emitFile=false!./file.png");
28-
// => returns the public url but does NOT emit a file
29-
// => returns i. e. "/public-path/0dcbbaa701328a3c262cfd45869e351f.png"
26+
// => 返回public url 但是不输出文件
27+
// => 即返回 "/public-path/0dcbbaa701328a3c262cfd45869e351f.png"
3028
```
3129

32-
#### Filename templates
30+
#### 文件名模板
3331

34-
You can configure a custom filename template for your file using the query parameter `name`. For instance, to copy a file from your `context` directory into the output directory retaining the full directory structure, you might use `?name=[path][name].[ext]`.
32+
你可以使用查询参数 `name` 为你的文件配置自定义的文件名模板。例如,从你的 `context` 目录复制文件到输出目录,并且保留完整的目录结构,你可以使用 `?name=[path][name].[ext]`
3533

36-
By default, the path and name you specify will output the file in that same directory and will also use that same URL path to access the file.
34+
默认情况下,会按照你指定的路径和文件名输出文件,且使用相同的 URL 路径来访问文件。
3735

38-
You can specify custom output and public paths by using the `outputPath` and `publicPath` query name parameters:
36+
你可以使用 `outputPath` `publicPath` 查询名称参数来指定自定义的输出路径和发布目录。
3937

4038
```
4139
use: "file-loader?name=[name].[ext]&publicPath=assets/foo/&outputPath=app/images/"
4240
```
4341

44-
#### Filename template placeholders
42+
#### 文件名模板占位符
4543

46-
* `[ext]` the extension of the resource
47-
* `[name]` the basename of the resource
48-
* `[path]` the path of the resource relative to the `context` query parameter or option.
49-
* `[hash]` the hash of the content, `hex`-encoded `md5` by default
50-
* `[<hashType>:hash:<digestType>:<length>]` optionally you can configure
51-
* other `hashType`s, i. e. `sha1`, `md5`, `sha256`, `sha512`
52-
* other `digestType`s, i. e. `hex`, `base26`, `base32`, `base36`, `base49`, `base52`, `base58`, `base62`, `base64`
53-
* and `length` the length in chars
54-
* `[N]` the N-th match obtained from matching the current file name against the query param `regExp`
55-
56-
#### Examples
44+
* `[ext]` 资源扩展名
45+
* `[name]` 资源的基本名称
46+
* `[path]` 资源相对于 `context` 查询参数或者配置的路径
47+
* `[hash]` 内容的哈希值,默认为十六进制编码的 `md5`
48+
* `[<hashType>:hash:<digestType>:<length>]` 可选配置
49+
* 其他的 `hashType`, 即 `sha1`, `md5`, `sha256`, `sha512`
50+
* 其他的 `digestType`, 即 `hex`, `base26`, `base32`, `base36`, `base49`, `base52`, `base58`, `base62`, `base64`
51+
* `length` 字符的长度
52+
* `[N]` 当前文件名按照查询参数 `regExp` 匹配后获得到第 N 个匹配结果
53+
#### 示例
5754

5855
``` javascript
5956
require("file-loader?name=js/[hash].script.[ext]!./javascript.js");
@@ -67,11 +64,11 @@ require("file-loader?name=[hash]!./flash.txt");
6764

6865
require("file-loader?name=[sha512:hash:base64:7].[ext]!./image.png");
6966
// => gdyb21L.png
70-
// use sha512 hash instead of md5 and with only 7 chars of base64
67+
// 使用 sha512 哈希值替代 md5 并且使用 base64 的 7 个字符
7168

7269
require("file-loader?name=img-[sha512:hash:base64:7].[ext]!./image.jpg");
7370
// => img-VqzT5ZC.jpg
74-
// use custom name, sha512 hash instead of md5 and with only 7 chars of base64
71+
// 使用自定义名称,sha512 哈希值替代 md5 并且使用 base64 的 7 个字符
7572

7673
require("file-loader?name=picture.png!./myself.png");
7774
// => picture.png
@@ -80,11 +77,11 @@ require("file-loader?name=[path][name].[ext]?[hash]!./dir/file.png")
8077
// => dir/file.png?e43b20c069c4a01867c31e98cbce33c9
8178
```
8279

83-
## Contributing
80+
## 贡献
8481

85-
Don't hesitate to create a pull request. Every contribution is appreciated. In development you can start the tests by calling `npm test`.
82+
不要犹豫去创建一个pull request。所有的贡献行为都会被感谢。开发时,可以使用 `npm test` 来进行测试。
8683

87-
## Maintainers
84+
## 维护人员
8885

8986
<table>
9087
<tbody>

0 commit comments

Comments
 (0)