You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3 年之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. # Webpack Manifest Plugin [![Build Status](https://travis-ci.org/danethurber/webpack-manifest-plugin.svg?branch=master)](https://travis-ci.org/danethurber/webpack-manifest-plugin) [![codecov](https://codecov.io/gh/danethurber/webpack-manifest-plugin/badge.svg?branch=master)](https://codecov.io/gh/danethurber/webpack-manifest-plugin?branch=master) [![Gitter](https://img.shields.io/gitter/room/nwjs/nw.js.svg)](https://gitter.im/webpack-manifest-plugin#)
  2. Webpack plugin for generating an asset manifest.
  3. > NOTE: The following is related to the next major version of `webpack-manifest-plugin`, please check https://github.com/danethurber/webpack-manifest-plugin/blob/1.x/README.md for `v1` documentation
  4. ## Install
  5. ```bash
  6. npm install --save-dev webpack-manifest-plugin
  7. ```
  8. ## Usage
  9. In your `webpack.config.js`
  10. ```javascript
  11. var ManifestPlugin = require('webpack-manifest-plugin');
  12. module.exports = {
  13. // ...
  14. plugins: [
  15. new ManifestPlugin()
  16. ]
  17. };
  18. ```
  19. This will generate a `manifest.json` file in your root output directory with a mapping of all source file names to their corresponding output file, for example:
  20. ```json
  21. {
  22. "mods/alpha.js": "mods/alpha.1234567890.js",
  23. "mods/omega.js": "mods/omega.0987654321.js"
  24. }
  25. ```
  26. ## API:
  27. ```js
  28. // webpack.config.js
  29. module.exports = {
  30. output: {
  31. publicPath
  32. },
  33. plugins: [
  34. new ManifestPlugin(options)
  35. ]
  36. }
  37. ```
  38. ### `options.fileName`
  39. Type: `String`<br>
  40. Default: `manifest.json`
  41. The manifest filename in your output directory.
  42. ### `options.publicPath`
  43. Type: `String`
  44. Default: `output.publicPath`
  45. A path prefix that will be added to values of the manifest.
  46. ### `options.basePath`
  47. Type: `String`
  48. A path prefix for all keys. Useful for including your output path in the manifest.
  49. ### `options.writeToFileEmit`
  50. Type: `Boolean`<br>
  51. Default: `false`
  52. If set to `true` will emit to build folder and memory in combination with `webpack-dev-server`
  53. ### `options.seed`
  54. Type: `Object`<br>
  55. Default: `{}`
  56. A cache of key/value pairs to used to seed the manifest. This may include a set of [custom key/value](https://developer.mozilla.org/en-US/Add-ons/WebExtensions/manifest.json) pairs to include in your manifest, or may be used to combine manifests across compilations in [multi-compiler mode](https://github.com/webpack/webpack/tree/master/examples/multi-compiler). To combine manifests, pass a shared seed object to each compiler's ManifestPlugin instance.
  57. ### `options.filter`
  58. Type: `Function(FileDescriptor): Boolean`
  59. Filter out files. [FileDescriptor typings](#filedescriptor)
  60. ### `options.map`
  61. Type: `Function(FileDescriptor): FileDescriptor`
  62. Modify files details before the manifest is created. [FileDescriptor typings](#filedescriptor)
  63. ### `options.sort`
  64. Type: `Function(FileDescriptor): number`
  65. Sort files before they are passed to `generate`. [FileDescriptor typings](#filedescriptor)
  66. ### `options.generate`
  67. Type: `Function(Object, FileDescriptor): Object`<br>
  68. Default: `(seed, files) => files.reduce((manifest, {name, path}) => ({...manifest, [name]: path}), seed)`
  69. Create the manifest. It can return anything as long as it's serialisable by `JSON.stringify`. [FileDescriptor typings](#filedescriptor)
  70. ### `options.serialize`
  71. Type: `Function(Object): string`<br>
  72. Default: `(manifest) => JSON.stringify(manifest, null, 2)`
  73. Output manifest file in different format then json (i.e. yaml).
  74. ## FileDescriptor
  75. ```ts
  76. FileDescriptor {
  77. path: string;
  78. name: string | null;
  79. isInitial: boolean;
  80. isChunk: boolean;
  81. chunk?: Chunk;
  82. isAsset: boolean;
  83. isModuleAsset: boolean;
  84. }
  85. ```
  86. ### `chunk`
  87. Type: [`Chunk`](https://github.com/webpack/webpack/blob/master/lib/Chunk.js)
  88. Only available is `isChunk` is `true`
  89. ### `isInitial`
  90. Type: `Boolean`
  91. Is required to run you app. Cannot be `true` if `isChunk` is `false`.
  92. ### `isModuleAsset`
  93. Type: `Boolean`
  94. Is required by a module. Cannot be `true` if `isAsset` is `false`.
  95. ## License
  96. MIT © [Dane Thurber](https://github.com/danethurber)