Open Christian-Yang opened 7 years ago
webpack starter中的代码 webpack.common.js
/**
* File loader for supporting images, for example, in CSS files.
* 文件 loader 支持 images ,例如在css 文件
*/
{
test: /\.(jpg|png|gif)$/,
use: 'file-loader'
},
/* File loader for supporting fonts, for example, in CSS files.
文件 loader 支持 fonts ,例如在css 文件
*/
{
test: /\.(eot|woff2?|svg|ttf)([\?]?.*)$/,
use: 'file-loader'
}
https://github.com/webpack-contrib/file-loader
file loader for webpack webpack的文件加载器
File Loader
Instructs webpack to emit the required object as file and to return its public url. 指示webpack将所需对象作为文件发出,并返回其公共URL。
Usage
By default the filename of the resulting file is the MD5 hash of the file's contents with the original extension of the required resource. 默认情况下,生成的文件的文件名是文件内容的MD5哈希值,并且具有所需资源的原始扩展名。
【重点在下面这里,就是这段代码】
By default a file is emitted, however this can be disabled if required (e.g. for server side packages). 默认情况下,文件会被emitted到指定的文件夹,但是这个也可以被禁止的。
Filename templates
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]. 您可以使用(查询参数名称)为文件配置(自定义文件名模板)。 例如,要将文件从上下文目录复制到保留完整目录结构的输出目录中,可以使用
?name = [path] [name].[ext]
。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. 默认情况下,您指定的路径和名称将在同一目录中输出文件,并且还将使用相同的URL路径来访问该文件。
You can specify custom output and public paths by using the outputPath, publicPath and useRelativePath query name parameters:
您可以使用outputPath,publicPath和useRelativePath查询名称参数来指定自定义输出和公共路径:
use: "file-loader?name=[name].[ext]&publicPath=assets/foo/&outputPath=app/images/"
useRelativePath
should betrue
if you wish to generate relative URL to the each file context如果您希望为每个文件上下文生成相对URL,则useRelativePath应为true
Filename template placeholders 文件名模板占位符
Examples