1. Webpack Manifest Plugin
用来生成资产清单的Webpack plugin。
注意: 下面是关于
webpack-manifest-plugin的下一个主要版本, 请查看 https://github.com/danethurber/webpack-manifest-plugin/blob/1.x/README.md 获取v1文档。
1.1. 安装
npm install --save-dev webpack-manifest-plugin
1.2. 用法
在你的 webpack.config.js文件中
var ManifestPlugin = require('webpack-manifest-plugin');
module.exports = {
// ...
plugins: [
new ManifestPlugin()
]
};
这将生成一个manifest.json文件在你的根输出目录,文件记录了所有源文件名映射到对应的输出文件的信息,例如:
{
"mods/alpha.js": "mods/alpha.1234567890.js",
"mods/omega.js": "mods/omega.0987654321.js"
}
1.3. API:
// webpack.config.js
module.exports = {
output: {
publicPath
},
plugins: [
new ManifestPlugin(options)
]
}
1.3.1. publicPath
类型: String
publicPath是一个路径前缀,将被添加到manifest的值中。
1.3.2. options.fileName
类型: String
默认值: manifest.json
在输出目录的manifest文件名。
1.3.3. options.basePath
类型: String
所有键的路径前缀。用于在manifest中包括输出路径。
1.3.4. options.writeToFileEmit
类型: Boolean
默认值: false
如果设置为true,将与webpack-dev-server结合,一起(emit)构建文件夹和内存
1.3.5. options.seed
类型: Object
默认值: {}
A cache of key/value pairs to used to seed the manifest. This may include a set of custom key/value pairs to include in your manifest, or may be used to combine manifests across compilations in multi-compiler mode. To combine manifests, pass a shared seed object to each compiler's ManifestPlugin instance.
用于对manifest进seed的键/值对的缓存。这可能包括在您的清单中包含的一组自定义键/值对,或者可以用于在多编译器模式中跨编译组合显示。为了合并显示,将一个共享的种子对象传递给每个编译器的manifest插件实例。
1.3.6. options.filter
Type: function
Filter out files. more details
1.3.7. options.map
Type: function
Modify files details before the manifest is created. more details
1.3.8. options.sort
Type: function
Sort files before they are passed to generate. more details
1.3.9. options.generate
Type: function
Default: (seed, files) => files.reduce((manifest, {name, path}) => ({...manifest, [name]: path}), seed)
All entries in files correspond to the object structure described in the Hooks Options section.
Create the manifest. It can return anything as long as it's serialisable by JSON.stringify. more details
1.4. Hooks Options
filter, map, sort takes as an input an Object with the following properties:
1.4.1. path
Type: String
1.4.2. chunk
Type: Chunk
1.4.3. name
Type: String, null
1.4.4. isChunk
Type: Boolean
1.4.5. isInitial
Type: Boolean
Is required to run you app. Cannot be true if isChunk is false.
1.4.6. isAsset
Type: Boolean
1.4.7. isModuleAsset
Type: Boolean
Is required by a module. Cannot be true if isAsset is false.
1.5. License
MIT © Dane Thurber