rspack-manifest-plugin 5.0.0-alpha0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +270 -0
- package/dist/helpers.d.ts +23 -0
- package/dist/helpers.js +97 -0
- package/dist/helpers.js.map +1 -0
- package/dist/hooks.d.ts +24 -0
- package/dist/hooks.js +96 -0
- package/dist/hooks.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +62 -0
- package/dist/index.js.map +1 -0
- package/package.json +106 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) Dane Thurber <dane.thurber@gmail.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
[tests]: https://img.shields.io/circleci/project/github/shellscape/webpack-manifest-plugin.svg
|
|
2
|
+
[tests-url]: https://circleci.com/gh/shellscape/webpack-manifest-plugin
|
|
3
|
+
[cover]: https://codecov.io/gh/shellscape/webpack-manifest-plugin/branch/master/graph/badge.svg
|
|
4
|
+
[cover-url]: https://codecov.io/gh/shellscape/webpack-manifest-plugin
|
|
5
|
+
[size]: https://packagephobia.now.sh/badge?p=webpack-manifest-plugin
|
|
6
|
+
[size-url]: https://packagephobia.now.sh/result?p=webpack-manifest-plugin
|
|
7
|
+
|
|
8
|
+
<div align="center">
|
|
9
|
+
<img width="256" src="https://raw.githubusercontent.com/shellscape/webpack-manifest-plugin/master/assets/manifest.svg?sanitize=true" alt="webpack-manfiest-plugin"><br/><br/>
|
|
10
|
+
</div>
|
|
11
|
+
|
|
12
|
+
[![tests][tests]][tests-url]
|
|
13
|
+
[![cover][cover]][cover-url]
|
|
14
|
+
[![size][size]][size-url]
|
|
15
|
+
[](https://liberamanifesto.com)
|
|
16
|
+
|
|
17
|
+
# webpack-manifest-plugin
|
|
18
|
+
|
|
19
|
+
A Webpack plugin for generating an asset manifest.
|
|
20
|
+
|
|
21
|
+
:heart: Please consider [Sponsoring my work](https://github.com/sponsors/shellscape)
|
|
22
|
+
|
|
23
|
+
## Requirements
|
|
24
|
+
|
|
25
|
+
`webpack-manifest-plugin` is an [evergreen 🌲](./.github/FAQ.md#what-does-evergreen-mean) module.
|
|
26
|
+
|
|
27
|
+
This module requires an [Active LTS](https://github.com/nodejs/Release) Node version (v12.0.0+) and Webpack v5.0.0.
|
|
28
|
+
|
|
29
|
+
## Contributing
|
|
30
|
+
|
|
31
|
+
This repository leverages [pnpm](https://pnpm.js.org/) for dependency management.
|
|
32
|
+
|
|
33
|
+
To begin, please install `pnpm`:
|
|
34
|
+
|
|
35
|
+
```console
|
|
36
|
+
$ npm install pnpm -g
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Install
|
|
40
|
+
|
|
41
|
+
Using npm:
|
|
42
|
+
|
|
43
|
+
```console
|
|
44
|
+
npm install webpack-nano webpack-manifest-plugin --save-dev
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
_Note: We recommend using [webpack-nano](https://github.com/shellscape/webpack-nano), a very tiny, very clean webpack CLI._
|
|
48
|
+
|
|
49
|
+
## Usage
|
|
50
|
+
|
|
51
|
+
Create a `webpack.config.js` file:
|
|
52
|
+
|
|
53
|
+
```js
|
|
54
|
+
const { WebpackManifestPlugin } = require('webpack-manifest-plugin');
|
|
55
|
+
const options = { ... };
|
|
56
|
+
|
|
57
|
+
module.exports = {
|
|
58
|
+
// an example entry definition
|
|
59
|
+
entry: [ 'app.js' ],
|
|
60
|
+
...
|
|
61
|
+
plugins: [
|
|
62
|
+
new WebpackManifestPlugin(options)
|
|
63
|
+
]
|
|
64
|
+
};
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
And run `webpack`:
|
|
68
|
+
|
|
69
|
+
```console
|
|
70
|
+
$ npx wp
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
With the default options, the example above will create a `manifest.json` file in the output directory for the build. The manifest file will contain a map of source filenames to the corresponding build output file. e.g.
|
|
74
|
+
|
|
75
|
+
```json
|
|
76
|
+
{
|
|
77
|
+
"dist/batman.js": "dist/batman.1234567890.js",
|
|
78
|
+
"dist/joker.js": "dist/joker.0987654321.js"
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Options
|
|
83
|
+
|
|
84
|
+
### `assetHookStage`
|
|
85
|
+
|
|
86
|
+
Type: `Number`<br>
|
|
87
|
+
Default: `Infinity`
|
|
88
|
+
|
|
89
|
+
If you need to consume the output of this plugin in another plugin, it can be useful to adjust the stage at which the manifest is generated. Pass a new stage to `assetHookStage` to change when the manifest is generated. See the [docs on `processAssets`](https://webpack.js.org/api/compilation-hooks/#list-of-asset-processing-stages) for more detail.
|
|
90
|
+
|
|
91
|
+
Note: any files added to the compilation after the stage specified will not be included in the manifest.
|
|
92
|
+
|
|
93
|
+
### `basePath`
|
|
94
|
+
|
|
95
|
+
Type: `String`<br>
|
|
96
|
+
Default: `''`
|
|
97
|
+
|
|
98
|
+
Specifies a path prefix for all keys in the manifest. Useful for including your output path in the manifest.
|
|
99
|
+
|
|
100
|
+
### `fileName`
|
|
101
|
+
|
|
102
|
+
Type: `String`<br>
|
|
103
|
+
Default: `manifest.json`
|
|
104
|
+
|
|
105
|
+
Specifies the file name to use for the resulting manifest. By default the plugin will emit `manifest.json` to your output directory. Passing an absolute path to the `fileName` option will override both the file name and path.
|
|
106
|
+
|
|
107
|
+
### `filter`
|
|
108
|
+
|
|
109
|
+
Type: `Function`<br>
|
|
110
|
+
Default: `undefined`
|
|
111
|
+
|
|
112
|
+
Allows filtering the files which make up the manifest. The passed function should match the signature of `(file: FileDescriptor) => Boolean`. Return `true` to keep the file, `false` to remove the file.
|
|
113
|
+
|
|
114
|
+
### `generate`
|
|
115
|
+
|
|
116
|
+
Type: `Function`<br>
|
|
117
|
+
Default: `undefined`
|
|
118
|
+
|
|
119
|
+
A custom `Function` to create the manifest. The passed function should match the signature of `(seed: Object, files: FileDescriptor[], entries: string[]) => Object` and can return anything as long as it's serialisable by `JSON.stringify`.
|
|
120
|
+
|
|
121
|
+
### `map`
|
|
122
|
+
|
|
123
|
+
Type: `Function`<br>
|
|
124
|
+
Default: `undefined`
|
|
125
|
+
|
|
126
|
+
Allows modifying the files which make up the manifest. The passed function should match the signature of `(file: FileDescriptor) => FileDescriptor` where an object matching `FileDescriptor` is returned.
|
|
127
|
+
|
|
128
|
+
### `publicPath`
|
|
129
|
+
|
|
130
|
+
Type: `String`<br>
|
|
131
|
+
Default: `<webpack-config>.output.publicPath`
|
|
132
|
+
|
|
133
|
+
A path prefix that will be added to values of the manifest.
|
|
134
|
+
|
|
135
|
+
### `removeKeyHash`
|
|
136
|
+
|
|
137
|
+
Type: `RegExp | false`<br>
|
|
138
|
+
Default: `/([a-f0-9]{32}\.?)/gi`
|
|
139
|
+
|
|
140
|
+
If set to a valid `RegExp`, removes hashes from manifest keys. e.g.
|
|
141
|
+
|
|
142
|
+
```json
|
|
143
|
+
{
|
|
144
|
+
"index.c5a9bff71fdfed9b6046.html": "index.c5a9bff71fdfed9b6046.html"
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
```json
|
|
149
|
+
{
|
|
150
|
+
"index.html": "index.c5a9bff71fdfed9b6046.html"
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
The default value for this option is a regular expression targeting Webpack's [default md5 hash](https://webpack.js.org/configuration/output/#outputhashfunction). To target other hashing functions / algorithms, set this option to an appropriate `RegExp`. To disable replacing the hashes in key names, set this option to `false`.
|
|
155
|
+
|
|
156
|
+
### `seed`
|
|
157
|
+
|
|
158
|
+
Type: `Object`<br>
|
|
159
|
+
Default: `{}`
|
|
160
|
+
|
|
161
|
+
A cache of key/value pairs 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 `WebpackManifestPlugin` instance.
|
|
162
|
+
|
|
163
|
+
### `serialize`
|
|
164
|
+
|
|
165
|
+
Type: `Function(Object) => string`<br>
|
|
166
|
+
Default: `undefined`
|
|
167
|
+
|
|
168
|
+
A `Function` which can be leveraged to serialize the manifest in a different format than json. e.g. `yaml`.
|
|
169
|
+
|
|
170
|
+
### `sort`
|
|
171
|
+
|
|
172
|
+
Type: `Function`<br>
|
|
173
|
+
Default: `undefined`
|
|
174
|
+
|
|
175
|
+
Allows sorting the files which make up the manifest. The passed function should match the signature of `(fileA: FileDescriptor, fileB: FileDescriptor) => Number`. Return `0` to indicate no change, `-1` to indicate the file should be moved to a lower index, and `1` to indicate the file shoud be moved to a higher index.
|
|
176
|
+
|
|
177
|
+
### `useEntryKeys`
|
|
178
|
+
|
|
179
|
+
Type: `Boolean`<br>
|
|
180
|
+
Default: `false`
|
|
181
|
+
|
|
182
|
+
If `true`, the keys specified in the `entry` property will be used as keys in the manifest. No file extension will be added (unless specified as part of an `entry` property key).
|
|
183
|
+
|
|
184
|
+
### `useLegacyEmit`
|
|
185
|
+
|
|
186
|
+
Type: `Boolean`<br>
|
|
187
|
+
Default: `false`
|
|
188
|
+
|
|
189
|
+
If `true`, the manifest will be written on the deprecated webpack `emit` hook to be compatible with not yet updated webpack plugins.
|
|
190
|
+
|
|
191
|
+
A lot of webpack plugins are not yet updated to match the new webpack 5 API. This is a problem when other plugins use the deprecated `emit` hook. The manifest will be written before these other plugins and thus files are missing on the manifest.
|
|
192
|
+
|
|
193
|
+
### `writeToFileEmit`
|
|
194
|
+
|
|
195
|
+
Type: `Boolean`<br>
|
|
196
|
+
Default: `false`
|
|
197
|
+
|
|
198
|
+
If `true`, will emit the manifest to the build directory _and_ in memory for compatibility with `webpack-dev-server`.
|
|
199
|
+
|
|
200
|
+
## Manifest File Descriptor
|
|
201
|
+
|
|
202
|
+
This plugin utilizes the following object structure to work with files. Many options for this plugin utilize the structure below.
|
|
203
|
+
|
|
204
|
+
```ts
|
|
205
|
+
{
|
|
206
|
+
chunk?: Chunk;
|
|
207
|
+
isAsset: boolean;
|
|
208
|
+
isChunk: boolean;
|
|
209
|
+
isInitial: boolean;
|
|
210
|
+
isModuleAsset: boolean;
|
|
211
|
+
name: string | null;
|
|
212
|
+
path: string;
|
|
213
|
+
}
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### `chunk`
|
|
217
|
+
|
|
218
|
+
Type: [`Chunk`](https://github.com/webpack/webpack/blob/master/lib/Chunk.js)
|
|
219
|
+
|
|
220
|
+
Only available if `isChunk` is `true`
|
|
221
|
+
|
|
222
|
+
### `isInitial`
|
|
223
|
+
|
|
224
|
+
Type: `Boolean`
|
|
225
|
+
|
|
226
|
+
Is required to run you app. Cannot be `true` if `isChunk` is `false`.
|
|
227
|
+
|
|
228
|
+
### `isModuleAsset`
|
|
229
|
+
|
|
230
|
+
Type: `Boolean`
|
|
231
|
+
|
|
232
|
+
Is required by a module. Cannot be `true` if `isAsset` is `false`.
|
|
233
|
+
|
|
234
|
+
## Compiler Hooks
|
|
235
|
+
|
|
236
|
+
This plugin supports the following hooks via the `getCompilerHooks` export; `afterEmit`, `beforeEmit`. These hooks can be useful, e.g. changing manifest contents before emitting to disk.
|
|
237
|
+
|
|
238
|
+
### `getCompilerHooks`
|
|
239
|
+
|
|
240
|
+
Returns: `{ afterEmit: SyncWaterfallHook, beforeEmit: SyncWaterfallHook }`
|
|
241
|
+
|
|
242
|
+
#### Usage
|
|
243
|
+
|
|
244
|
+
```js
|
|
245
|
+
const { getCompilerHooks } = require('webpack-manifest-plugin');
|
|
246
|
+
|
|
247
|
+
class BatmanPlugin {
|
|
248
|
+
apply(compiler) {
|
|
249
|
+
const { beforeEmit } = getCompilerHooks(compiler);
|
|
250
|
+
|
|
251
|
+
beforeEmit.tap('BatmanPlugin', (manifest) => {
|
|
252
|
+
return { ...manifest, name: 'hello' };
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
## Notes
|
|
259
|
+
|
|
260
|
+
- If using this plugin with `webpack-clean` and `webpack-dev-server`, please review [this issue](https://github.com/shellscape/webpack-manifest-plugin/issues/267).
|
|
261
|
+
|
|
262
|
+
## Attiribution
|
|
263
|
+
|
|
264
|
+
Special thanks to [Dane Thurber](https://github.com/danethurber), the original author of this plugin, without whom this plugin would not exist.
|
|
265
|
+
|
|
266
|
+
## Meta
|
|
267
|
+
|
|
268
|
+
[CONTRIBUTING](./.github/CONTRIBUTING.md)
|
|
269
|
+
|
|
270
|
+
[LICENSE (MIT)](./LICENSE)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { AssetInfo, Chunk, Asset, Compilation } from 'webpack';
|
|
2
|
+
import { InternalOptions, Manifest } from './';
|
|
3
|
+
export interface FileDescriptor {
|
|
4
|
+
chunk?: Chunk;
|
|
5
|
+
isAsset: Boolean;
|
|
6
|
+
isChunk: Boolean;
|
|
7
|
+
isInitial: Boolean;
|
|
8
|
+
isModuleAsset: Boolean;
|
|
9
|
+
name: string;
|
|
10
|
+
path: string;
|
|
11
|
+
}
|
|
12
|
+
export interface CompilationAssetInfo extends AssetInfo {
|
|
13
|
+
sourceFilename: string;
|
|
14
|
+
}
|
|
15
|
+
export interface CompilationAsset extends Asset {
|
|
16
|
+
chunks: any[];
|
|
17
|
+
info: CompilationAssetInfo;
|
|
18
|
+
}
|
|
19
|
+
declare const generateManifest: (compilation: Compilation, files: FileDescriptor[], { generate, seed }: InternalOptions) => Manifest;
|
|
20
|
+
declare const reduceAssets: (files: FileDescriptor[], asset: CompilationAsset, moduleAssets: Record<any, any>) => FileDescriptor[];
|
|
21
|
+
declare const reduceChunk: (files: FileDescriptor[], chunk: Chunk, options: InternalOptions, auxiliaryFiles: Record<any, any>) => FileDescriptor[];
|
|
22
|
+
declare const transformFiles: (files: FileDescriptor[], options: InternalOptions) => FileDescriptor[];
|
|
23
|
+
export { generateManifest, reduceAssets, reduceChunk, transformFiles };
|
package/dist/helpers.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformFiles = exports.reduceChunk = exports.reduceAssets = exports.generateManifest = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const generateManifest = (compilation, files, { generate, seed = {} }) => {
|
|
6
|
+
let result;
|
|
7
|
+
if (generate) {
|
|
8
|
+
const entrypointsArray = Array.from(compilation.entrypoints.entries());
|
|
9
|
+
const entrypoints = entrypointsArray.reduce((e, [name, entrypoint]) => Object.assign(e, { [name]: entrypoint.getFiles() }), {});
|
|
10
|
+
result = generate(seed, files, entrypoints);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
result = files.reduce((manifest, file) => Object.assign(manifest, { [file.name]: file.path }), seed);
|
|
14
|
+
}
|
|
15
|
+
return result;
|
|
16
|
+
};
|
|
17
|
+
exports.generateManifest = generateManifest;
|
|
18
|
+
const getFileType = (fileName, { transformExtensions }) => {
|
|
19
|
+
const replaced = fileName.replace(/\?.*/, '');
|
|
20
|
+
const split = replaced.split('.');
|
|
21
|
+
const extension = split.pop();
|
|
22
|
+
return transformExtensions.test(extension) ? `${split.pop()}.${extension}` : extension;
|
|
23
|
+
};
|
|
24
|
+
const reduceAssets = (files, asset, moduleAssets) => {
|
|
25
|
+
let name;
|
|
26
|
+
if (moduleAssets[asset.name]) {
|
|
27
|
+
name = moduleAssets[asset.name];
|
|
28
|
+
}
|
|
29
|
+
else if (asset.info.sourceFilename) {
|
|
30
|
+
name = (0, path_1.join)((0, path_1.dirname)(asset.name), (0, path_1.basename)(asset.info.sourceFilename));
|
|
31
|
+
}
|
|
32
|
+
if (name) {
|
|
33
|
+
return files.concat({
|
|
34
|
+
isAsset: true,
|
|
35
|
+
isChunk: false,
|
|
36
|
+
isInitial: false,
|
|
37
|
+
isModuleAsset: true,
|
|
38
|
+
name,
|
|
39
|
+
path: asset.name
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
const isEntryAsset = asset.chunks && asset.chunks.length > 0;
|
|
43
|
+
if (isEntryAsset) {
|
|
44
|
+
return files;
|
|
45
|
+
}
|
|
46
|
+
return files.concat({
|
|
47
|
+
isAsset: true,
|
|
48
|
+
isChunk: false,
|
|
49
|
+
isInitial: false,
|
|
50
|
+
isModuleAsset: false,
|
|
51
|
+
name: asset.name,
|
|
52
|
+
path: asset.name
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
exports.reduceAssets = reduceAssets;
|
|
56
|
+
const reduceChunk = (files, chunk, options, auxiliaryFiles) => {
|
|
57
|
+
Array.from(chunk.auxiliaryFiles || []).forEach((auxiliaryFile) => {
|
|
58
|
+
auxiliaryFiles[auxiliaryFile] = {
|
|
59
|
+
isAsset: true,
|
|
60
|
+
isChunk: false,
|
|
61
|
+
isInitial: false,
|
|
62
|
+
isModuleAsset: true,
|
|
63
|
+
name: (0, path_1.basename)(auxiliaryFile),
|
|
64
|
+
path: auxiliaryFile
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
return Array.from(chunk.files).reduce((prev, path) => {
|
|
68
|
+
let name = chunk.name ? chunk.name : null;
|
|
69
|
+
name = name
|
|
70
|
+
? options.useEntryKeys && !path.endsWith('.map')
|
|
71
|
+
? name
|
|
72
|
+
: `${name}.${getFileType(path, options)}`
|
|
73
|
+
: path;
|
|
74
|
+
return prev.concat({
|
|
75
|
+
chunk,
|
|
76
|
+
isAsset: false,
|
|
77
|
+
isChunk: true,
|
|
78
|
+
isInitial: chunk.isOnlyInitial(),
|
|
79
|
+
isModuleAsset: false,
|
|
80
|
+
name,
|
|
81
|
+
path
|
|
82
|
+
});
|
|
83
|
+
}, files);
|
|
84
|
+
};
|
|
85
|
+
exports.reduceChunk = reduceChunk;
|
|
86
|
+
const standardizeFilePaths = (file) => {
|
|
87
|
+
const result = Object.assign({}, file);
|
|
88
|
+
result.name = file.name.replace(/\\/g, '/');
|
|
89
|
+
result.path = file.path.replace(/\\/g, '/');
|
|
90
|
+
return result;
|
|
91
|
+
};
|
|
92
|
+
const transformFiles = (files, options) => ['filter', 'map', 'sort']
|
|
93
|
+
.filter((fname) => !!options[fname])
|
|
94
|
+
.reduce((prev, fname) => prev[fname](options[fname]), files)
|
|
95
|
+
.map(standardizeFilePaths);
|
|
96
|
+
exports.transformFiles = transformFiles;
|
|
97
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":";;;AAAA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IACvC,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAC5C,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAC5C,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAEF,MAAM,cAAc,GAAG,CAAC,KAAuB,EAAE,OAAwB,EAAE,EAAE,CAC3E,CAAC,QAAQ,EAAE,KAAK,EAAE,MAAM,CAAC;KACtB,MAAM,CAAC,CAAC,KAAa,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;KAE3C,MAAM,CAGL,CAAC,IAAI,EAAE,KAAa,EAAE,EAAE,CAAE,IAA4C,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAC7F,KAAK,CACN;KACA,GAAG,CAAC,oBAAoB,CAAC,CAAC;AAEuB,wCAAc"}
|
package/dist/hooks.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Compiler, Module, Compilation, LoaderContext } from 'webpack';
|
|
2
|
+
import { EmitCountMap, InternalOptions } from './';
|
|
3
|
+
interface BeforeRunHookArgs {
|
|
4
|
+
emitCountMap: EmitCountMap;
|
|
5
|
+
manifestFileName: string;
|
|
6
|
+
}
|
|
7
|
+
interface EmitHookArgs {
|
|
8
|
+
compiler: Compiler;
|
|
9
|
+
emitCountMap: EmitCountMap;
|
|
10
|
+
manifestAssetId: string;
|
|
11
|
+
manifestFileName: string;
|
|
12
|
+
moduleAssets: Record<any, any>;
|
|
13
|
+
options: InternalOptions;
|
|
14
|
+
}
|
|
15
|
+
declare const getCompilerHooks: (compiler: Compiler) => any;
|
|
16
|
+
declare const beforeRunHook: ({ emitCountMap, manifestFileName }: BeforeRunHookArgs, _: Compiler, callback: Function) => void;
|
|
17
|
+
declare const emitHook: ({ compiler, emitCountMap, manifestAssetId, manifestFileName, moduleAssets, options }: EmitHookArgs, compilation: Compilation) => void;
|
|
18
|
+
interface LegacyModule extends Module {
|
|
19
|
+
userRequest?: any;
|
|
20
|
+
}
|
|
21
|
+
declare const normalModuleLoaderHook: ({ moduleAssets }: {
|
|
22
|
+
moduleAssets: Record<any, any>;
|
|
23
|
+
}, loaderContext: LoaderContext<any>, module: LegacyModule) => void;
|
|
24
|
+
export { beforeRunHook, emitHook, getCompilerHooks, normalModuleLoaderHook };
|
package/dist/hooks.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalModuleLoaderHook = exports.getCompilerHooks = exports.emitHook = exports.beforeRunHook = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const tapable_1 = require("tapable");
|
|
7
|
+
const webpack_sources_1 = require("webpack-sources");
|
|
8
|
+
const helpers_1 = require("./helpers");
|
|
9
|
+
const compilerHookMap = new WeakMap();
|
|
10
|
+
const getCompilerHooks = (compiler) => {
|
|
11
|
+
let hooks = compilerHookMap.get(compiler);
|
|
12
|
+
if (typeof hooks === 'undefined') {
|
|
13
|
+
hooks = {
|
|
14
|
+
afterEmit: new tapable_1.SyncWaterfallHook(['manifest']),
|
|
15
|
+
beforeEmit: new tapable_1.SyncWaterfallHook(['manifest'])
|
|
16
|
+
};
|
|
17
|
+
compilerHookMap.set(compiler, hooks);
|
|
18
|
+
}
|
|
19
|
+
return hooks;
|
|
20
|
+
};
|
|
21
|
+
exports.getCompilerHooks = getCompilerHooks;
|
|
22
|
+
const beforeRunHook = ({ emitCountMap, manifestFileName }, _, callback) => {
|
|
23
|
+
const emitCount = emitCountMap.get(manifestFileName) || 0;
|
|
24
|
+
emitCountMap.set(manifestFileName, emitCount + 1);
|
|
25
|
+
if (callback) {
|
|
26
|
+
callback();
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
exports.beforeRunHook = beforeRunHook;
|
|
30
|
+
const emitHook = function emit({ compiler, emitCountMap, manifestAssetId, manifestFileName, moduleAssets, options }, compilation) {
|
|
31
|
+
const emitCount = emitCountMap.get(manifestFileName) - 1;
|
|
32
|
+
const stats = compilation.getStats().toJson({
|
|
33
|
+
all: false,
|
|
34
|
+
assets: true,
|
|
35
|
+
cachedAssets: true,
|
|
36
|
+
ids: true,
|
|
37
|
+
publicPath: true
|
|
38
|
+
});
|
|
39
|
+
const publicPath = options.publicPath !== null ? options.publicPath : stats.publicPath;
|
|
40
|
+
const { basePath, removeKeyHash } = options;
|
|
41
|
+
emitCountMap.set(manifestFileName, emitCount);
|
|
42
|
+
const auxiliaryFiles = {};
|
|
43
|
+
let files = Array.from(compilation.chunks).reduce((prev, chunk) => (0, helpers_1.reduceChunk)(prev, chunk, options, auxiliaryFiles), []);
|
|
44
|
+
files = stats.assets.reduce((prev, asset) => (0, helpers_1.reduceAssets)(prev, asset, moduleAssets), files);
|
|
45
|
+
files = files.filter(({ name, path }) => {
|
|
46
|
+
var _a;
|
|
47
|
+
return !path.includes('hot-update') &&
|
|
48
|
+
typeof emitCountMap.get((0, path_1.join)(((_a = compiler.options.output) === null || _a === void 0 ? void 0 : _a.path) || '<unknown>', name)) ===
|
|
49
|
+
'undefined';
|
|
50
|
+
});
|
|
51
|
+
files.forEach((file) => {
|
|
52
|
+
delete auxiliaryFiles[file.path];
|
|
53
|
+
});
|
|
54
|
+
Object.keys(auxiliaryFiles).forEach((auxiliaryFile) => {
|
|
55
|
+
files = files.concat(auxiliaryFiles[auxiliaryFile]);
|
|
56
|
+
});
|
|
57
|
+
files = files.map((file) => {
|
|
58
|
+
const normalizePath = (path) => {
|
|
59
|
+
if (!path.endsWith('/')) {
|
|
60
|
+
return `${path}/`;
|
|
61
|
+
}
|
|
62
|
+
return path;
|
|
63
|
+
};
|
|
64
|
+
const changes = {
|
|
65
|
+
name: basePath ? normalizePath(basePath) + file.name : file.name,
|
|
66
|
+
path: publicPath ? normalizePath(publicPath) + file.path : file.path
|
|
67
|
+
};
|
|
68
|
+
changes.name = removeKeyHash ? changes.name.replace(removeKeyHash, '') : changes.name;
|
|
69
|
+
return Object.assign(file, changes);
|
|
70
|
+
});
|
|
71
|
+
files = (0, helpers_1.transformFiles)(files, options);
|
|
72
|
+
let manifest = (0, helpers_1.generateManifest)(compilation, files, options);
|
|
73
|
+
const isLastEmit = emitCount === 0;
|
|
74
|
+
manifest = getCompilerHooks(compiler).beforeEmit.call(manifest);
|
|
75
|
+
if (isLastEmit) {
|
|
76
|
+
const output = options.serialize(manifest);
|
|
77
|
+
compilation.emitAsset(manifestAssetId, new webpack_sources_1.RawSource(output));
|
|
78
|
+
if (options.writeToFileEmit) {
|
|
79
|
+
(0, fs_1.mkdirSync)((0, path_1.dirname)(manifestFileName), { recursive: true });
|
|
80
|
+
(0, fs_1.writeFileSync)(manifestFileName, output);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
getCompilerHooks(compiler).afterEmit.call(manifest);
|
|
84
|
+
};
|
|
85
|
+
exports.emitHook = emitHook;
|
|
86
|
+
const normalModuleLoaderHook = ({ moduleAssets }, loaderContext, module) => {
|
|
87
|
+
const { emitFile } = loaderContext;
|
|
88
|
+
loaderContext.emitFile = (file, content, sourceMap) => {
|
|
89
|
+
if (module.userRequest && !moduleAssets[file]) {
|
|
90
|
+
Object.assign(moduleAssets, { [file]: (0, path_1.join)((0, path_1.dirname)(file), (0, path_1.basename)(module.userRequest)) });
|
|
91
|
+
}
|
|
92
|
+
return emitFile.call(module, file, content, sourceMap);
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
exports.normalModuleLoaderHook = normalModuleLoaderHook;
|
|
96
|
+
//# sourceMappingURL=hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":";;;AAAA,2BAA8C;AAC9C,+B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package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Compiler, WebpackPluginInstance } from 'webpack';
|
|
2
|
+
import { FileDescriptor } from './helpers';
|
|
3
|
+
import { getCompilerHooks } from './hooks';
|
|
4
|
+
export type Manifest = Record<string, any>;
|
|
5
|
+
export interface InternalOptions {
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
assetHookStage: number;
|
|
8
|
+
basePath: string;
|
|
9
|
+
fileName: string;
|
|
10
|
+
filter: (file: FileDescriptor) => Boolean;
|
|
11
|
+
generate: (seed: Record<any, any>, files: FileDescriptor[], entries: Record<string, string[]>) => Manifest;
|
|
12
|
+
map: (file: FileDescriptor) => FileDescriptor;
|
|
13
|
+
publicPath: string;
|
|
14
|
+
removeKeyHash: RegExp | false;
|
|
15
|
+
seed: Record<any, any>;
|
|
16
|
+
serialize: (manifest: Manifest) => string;
|
|
17
|
+
sort: (fileA: FileDescriptor, fileB: FileDescriptor) => Number;
|
|
18
|
+
transformExtensions: RegExp;
|
|
19
|
+
useEntryKeys: Boolean;
|
|
20
|
+
useLegacyEmit: Boolean;
|
|
21
|
+
writeToFileEmit: Boolean;
|
|
22
|
+
}
|
|
23
|
+
export type ManifestPluginOptions = Partial<InternalOptions>;
|
|
24
|
+
export type EmitCountMap = Map<any, any>;
|
|
25
|
+
declare class WebpackManifestPlugin implements WebpackPluginInstance {
|
|
26
|
+
private options;
|
|
27
|
+
constructor(opts: ManifestPluginOptions);
|
|
28
|
+
apply(compiler: Compiler): void;
|
|
29
|
+
}
|
|
30
|
+
export { getCompilerHooks, WebpackManifestPlugin };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WebpackManifestPlugin = exports.getCompilerHooks = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const hooks_1 = require("./hooks");
|
|
6
|
+
Object.defineProperty(exports, "getCompilerHooks", { enumerable: true, get: function () { return hooks_1.getCompilerHooks; } });
|
|
7
|
+
const emitCountMap = new Map();
|
|
8
|
+
const defaults = {
|
|
9
|
+
assetHookStage: Infinity,
|
|
10
|
+
basePath: '',
|
|
11
|
+
fileName: 'manifest.json',
|
|
12
|
+
filter: null,
|
|
13
|
+
generate: void 0,
|
|
14
|
+
map: null,
|
|
15
|
+
publicPath: null,
|
|
16
|
+
removeKeyHash: /([a-f0-9]{16,32}\.?)/gi,
|
|
17
|
+
seed: void 0,
|
|
18
|
+
serialize(manifest) {
|
|
19
|
+
return JSON.stringify(manifest, null, 2);
|
|
20
|
+
},
|
|
21
|
+
sort: null,
|
|
22
|
+
transformExtensions: /^(gz|map)$/i,
|
|
23
|
+
useEntryKeys: false,
|
|
24
|
+
useLegacyEmit: false,
|
|
25
|
+
writeToFileEmit: false
|
|
26
|
+
};
|
|
27
|
+
class WebpackManifestPlugin {
|
|
28
|
+
constructor(opts) {
|
|
29
|
+
this.options = Object.assign({}, defaults, opts);
|
|
30
|
+
}
|
|
31
|
+
apply(compiler) {
|
|
32
|
+
var _a, _b;
|
|
33
|
+
const moduleAssets = {};
|
|
34
|
+
const manifestFileName = (0, path_1.resolve)(((_a = compiler.options.output) === null || _a === void 0 ? void 0 : _a.path) || './', this.options.fileName);
|
|
35
|
+
const manifestAssetId = (0, path_1.relative)(((_b = compiler.options.output) === null || _b === void 0 ? void 0 : _b.path) || './', manifestFileName);
|
|
36
|
+
const beforeRun = hooks_1.beforeRunHook.bind(this, { emitCountMap, manifestFileName });
|
|
37
|
+
const emit = hooks_1.emitHook.bind(this, {
|
|
38
|
+
compiler,
|
|
39
|
+
emitCountMap,
|
|
40
|
+
manifestAssetId,
|
|
41
|
+
manifestFileName,
|
|
42
|
+
moduleAssets,
|
|
43
|
+
options: this.options
|
|
44
|
+
});
|
|
45
|
+
const hookOptions = {
|
|
46
|
+
name: 'WebpackManifestPlugin',
|
|
47
|
+
stage: this.options.assetHookStage
|
|
48
|
+
};
|
|
49
|
+
if (this.options.useLegacyEmit === true) {
|
|
50
|
+
compiler.hooks.emit.tap(hookOptions, emit);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
compiler.hooks.thisCompilation.tap(hookOptions, (compilation) => {
|
|
54
|
+
compilation.hooks.processAssets.tap(hookOptions, () => emit(compilation));
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
compiler.hooks.run.tapAsync(hookOptions, beforeRun);
|
|
58
|
+
compiler.hooks.watchRun.tapAsync(hookOptions, beforeRun);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.WebpackManifestPlugin = WebpackManifestPlugin;
|
|
62
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,+BAAyC;AAQzC,mCAAoE;AA2G3D,iGA3GyB,wBAAgB,OA2GzB;AAzGzB,MAAM,YAAY,GAAiB,IAAI,GAAG,EAAE,CAAC;AA6B7C,MAAM,QAAQ,GAAG;IACf,cAAc,EAAE,QAAQ;IACxB,QAAQ,EAAE,EAAE;IACZ,QAAQ,EAAE,eAAe;IACzB,MAAM,EAAE,IAAI;IACZ,QAAQ,EAAE,KAAK,CAAC;IAChB,GAAG,EAAE,IAAI;IACT,UAAU,EAAE,IAAI;IAChB,aAAa,EAAE,wBAAwB;IAEvC,IAAI,EAAE,KAAK,CAAC;IACZ,SAAS,CAAC,QAAa;QACrB,OAAO,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAC3C,CAAC;IACD,IAAI,EAAE,IAAI;IACV,mBAAmB,EAAE,aAAa;IAClC,YAAY,EAAE,KAAK;IACnB,aAAa,EAAE,KAAK;IACpB,eAAe,EAAE,KAAK;CACvB,CAAC;AAQF,MAAM,qBAAqB;IAEzB,YAAY,IAA2B;QACrC,IAAI,CAA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J,CAAC,CAAC,CAAC;SACJ;QAED,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;QACpD,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;IAC3D,CAAC;CACF;AAE0B,sDAAqB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "rspack-manifest-plugin",
|
|
3
|
+
"version": "5.0.0-alpha0",
|
|
4
|
+
"description": "A Webpack Plugin for generating Asset Manifests",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": "shellscape/webpack-manifest-plugin",
|
|
7
|
+
"author": "Dane Thurber <dane.thurber@gmail.com>",
|
|
8
|
+
"homepage": "https://github.com/shellscape/webpack-manifest-plugin",
|
|
9
|
+
"bugs": "https://github.com/shellscape/webpack-manifest-plugin/issues",
|
|
10
|
+
"main": "dist/index.js",
|
|
11
|
+
"engines": {
|
|
12
|
+
"node": ">=14"
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc --project tsconfig.json",
|
|
16
|
+
"ci:coverage": "nyc pnpm ci:test && nyc report --reporter=text-lcov > coverage.lcov",
|
|
17
|
+
"ci:lint": "pnpm lint && pnpm security",
|
|
18
|
+
"ci:test": "pnpm test -- --verbose",
|
|
19
|
+
"lint": "pnpm lint:docs && pnpm lint:json && pnpm lint:js",
|
|
20
|
+
"lint-staged": "lint-staged",
|
|
21
|
+
"lint:docs": "prettier --write README.md",
|
|
22
|
+
"lint:js": "eslint --cache --fix --cache src test",
|
|
23
|
+
"lint:json": "prettier --write codecov.yml package.json",
|
|
24
|
+
"prepare": "husky install",
|
|
25
|
+
"prepublishOnly": "pnpm lint && pnpm build",
|
|
26
|
+
"pretest": "pnpm install && pnpm build",
|
|
27
|
+
"security": "pnpm audit --audit-level=high --prod",
|
|
28
|
+
"test": "ava --timeout=2m"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"dist",
|
|
32
|
+
"README.md",
|
|
33
|
+
"LICENSE"
|
|
34
|
+
],
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"webpack": "^5.75.0"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"tapable": "^2.0.0",
|
|
40
|
+
"webpack-sources": "^2.2.0"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@ava/babel": "^1.0.1",
|
|
44
|
+
"@commitlint/cli": "^13.1.0",
|
|
45
|
+
"@commitlint/config-conventional": "^13.1.0",
|
|
46
|
+
"@svgr/webpack": "^5.4.0",
|
|
47
|
+
"@types/node": "^16.4.3",
|
|
48
|
+
"@types/webpack": "^5.28.0",
|
|
49
|
+
"@types/webpack-sources": "^2.1.1",
|
|
50
|
+
"@wordpress/dependency-extraction-webpack-plugin": "^3.1.0",
|
|
51
|
+
"ava": "^5.1.0",
|
|
52
|
+
"codecov": "^3.1.0",
|
|
53
|
+
"copy-webpack-plugin": "^6.2.1",
|
|
54
|
+
"del": "^6.0.0",
|
|
55
|
+
"eslint-config-shellscape": "^6.0.0",
|
|
56
|
+
"file-loader": "^6.2.0",
|
|
57
|
+
"husky": "8.0.2",
|
|
58
|
+
"lint-staged": "11.1.1",
|
|
59
|
+
"memory-fs": "^0.4.1",
|
|
60
|
+
"nyc": "^15.1.0",
|
|
61
|
+
"pre-commit": "^1.2.2",
|
|
62
|
+
"prettier": "^2.1.2",
|
|
63
|
+
"prettier-plugin-package": "^1.2.0",
|
|
64
|
+
"react": "^16.3.2",
|
|
65
|
+
"style-loader": "^0.23.0",
|
|
66
|
+
"ts-node": "^10.1.0",
|
|
67
|
+
"tslib": "^2.3.0",
|
|
68
|
+
"typescript": "^4.9.4",
|
|
69
|
+
"webpack": "^5.75.0",
|
|
70
|
+
"webpack-merge": "^5.8.0"
|
|
71
|
+
},
|
|
72
|
+
"ava": {
|
|
73
|
+
"files": [
|
|
74
|
+
"!**/fixtures/**",
|
|
75
|
+
"!**/helpers/**",
|
|
76
|
+
"!**/output/**"
|
|
77
|
+
]
|
|
78
|
+
},
|
|
79
|
+
"husky": {
|
|
80
|
+
"hooks": {
|
|
81
|
+
"pre-commit": "lint-staged"
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
"jest": {
|
|
85
|
+
"testEnvironment": "node",
|
|
86
|
+
"coverageDirectory": "./coverage/",
|
|
87
|
+
"collectCoverage": true
|
|
88
|
+
},
|
|
89
|
+
"lint-staged": {
|
|
90
|
+
"*.js": [
|
|
91
|
+
"eslint --fix"
|
|
92
|
+
]
|
|
93
|
+
},
|
|
94
|
+
"maintainers": [
|
|
95
|
+
"Andrew Powell <andrew@shellscape.org>"
|
|
96
|
+
],
|
|
97
|
+
"nyc": {
|
|
98
|
+
"include": [
|
|
99
|
+
"src/*.ts"
|
|
100
|
+
],
|
|
101
|
+
"exclude": [
|
|
102
|
+
"test/"
|
|
103
|
+
]
|
|
104
|
+
},
|
|
105
|
+
"pre-commit": "lint-staged"
|
|
106
|
+
}
|