|
7 | 7 | * @flow
|
8 | 8 | */
|
9 | 9 |
|
10 |
| -import {mkdirSync, writeFileSync} from 'fs'; |
11 |
| -import {dirname, resolve, join} from 'path'; |
| 10 | +import {join} from 'path'; |
12 | 11 | import {pathToFileURL} from 'url';
|
13 | 12 |
|
14 | 13 | import asyncLib from 'neo-async';
|
@@ -48,13 +47,16 @@ type Options = {
|
48 | 47 | isServer: boolean,
|
49 | 48 | clientReferences?: ClientReferencePath | $ReadOnlyArray<ClientReferencePath>,
|
50 | 49 | chunkName?: string,
|
| 50 | + manifestFilename?: string, |
51 | 51 | };
|
52 | 52 |
|
53 | 53 | const PLUGIN_NAME = 'React Transport Plugin';
|
54 | 54 |
|
55 | 55 | export default class ReactFlightWebpackPlugin {
|
56 | 56 | clientReferences: $ReadOnlyArray<ClientReferencePath>;
|
57 | 57 | chunkName: string;
|
| 58 | + manifestFilename: string; |
| 59 | + |
58 | 60 | constructor(options: Options) {
|
59 | 61 | if (!options || typeof options.isServer !== 'boolean') {
|
60 | 62 | throw new Error(
|
@@ -88,6 +90,8 @@ export default class ReactFlightWebpackPlugin {
|
88 | 90 | } else {
|
89 | 91 | this.chunkName = 'client[index]';
|
90 | 92 | }
|
| 93 | + this.manifestFilename = |
| 94 | + options.manifestFilename || 'react-client-manifest.json'; |
91 | 95 | }
|
92 | 96 |
|
93 | 97 | apply(compiler: any) {
|
@@ -189,13 +193,14 @@ export default class ReactFlightWebpackPlugin {
|
189 | 193 | });
|
190 | 194 | });
|
191 | 195 | const output = JSON.stringify(json, null, 2);
|
192 |
| - const filename = resolve( |
193 |
| - compiler.options.output.path, |
194 |
| - 'react-transport-manifest.json', |
195 |
| - ); |
196 |
| - mkdirSync(dirname(filename), {recursive: true}); |
197 |
| - // TODO: Use webpack's emit API and read from the devserver. |
198 |
| - writeFileSync(filename, output); |
| 196 | + compilation.assets[this.manifestFilename] = { |
| 197 | + source() { |
| 198 | + return output; |
| 199 | + }, |
| 200 | + size() { |
| 201 | + return output.length; |
| 202 | + }, |
| 203 | + }; |
199 | 204 | });
|
200 | 205 | }
|
201 | 206 |
|
|
0 commit comments