Skip to content

Commit 9e71f9d

Browse files
committed
Use assets API + writeToDisk instead of directly writing to disk
1 parent b66ae09 commit 9e71f9d

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

fixtures/flight/config/webpackDevServer.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ module.exports = function(proxy, allowedHost) {
7171
watchOptions: {
7272
ignored: ignoredFiles(paths.appSrc),
7373
},
74+
writeToDisk: (filePath) => {
75+
return /react-client-manifest\.json$/.test(filePath);
76+
},
7477
// Enable HTTPS if the HTTPS environment variable is set to 'true'
7578
https: protocol === 'https',
7679
host,

fixtures/flight/server/handler.server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = function(req, res) {
1010
import('../src/App.server.js').then(m => {
1111
const dist = process.env.NODE_ENV === 'development' ? 'dist' : 'build';
1212
readFile(
13-
resolve(__dirname, `../${dist}/react-transport-manifest.json`),
13+
resolve(__dirname, `../${dist}/react-client-manifest.json`),
1414
'utf8',
1515
(err, data) => {
1616
if (err) {

packages/react-transport-dom-webpack/src/ReactFlightWebpackPlugin.js

+13-7
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,16 @@ type Options = {
4848
isServer: boolean,
4949
clientReferences?: ClientReferencePath | $ReadOnlyArray<ClientReferencePath>,
5050
chunkName?: string,
51+
manifestFilename?: string,
5152
};
5253

5354
const PLUGIN_NAME = 'React Transport Plugin';
5455

5556
export default class ReactFlightWebpackPlugin {
5657
clientReferences: $ReadOnlyArray<ClientReferencePath>;
5758
chunkName: string;
59+
manifestFilename: string;
60+
5861
constructor(options: Options) {
5962
if (!options || typeof options.isServer !== 'boolean') {
6063
throw new Error(
@@ -88,6 +91,8 @@ export default class ReactFlightWebpackPlugin {
8891
} else {
8992
this.chunkName = 'client[index]';
9093
}
94+
this.manifestFilename =
95+
options.manifestFilename || 'react-client-manifest.json';
9196
}
9297

9398
apply(compiler: any) {
@@ -189,13 +194,14 @@ export default class ReactFlightWebpackPlugin {
189194
});
190195
});
191196
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);
197+
compilation.assets[this.manifestFilename] = {
198+
source() {
199+
return output;
200+
},
201+
size() {
202+
output.length;
203+
},
204+
};
199205
});
200206
}
201207

0 commit comments

Comments
 (0)