GeezerVison is showing github.com — Use assets API + writeToDisk instead of directly writing to disk (#20… · react/react@ce40f1d
File treeExpand file treeCollapse file tree Open diff view settings packages/react-transport-dom-webpack/src
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: fixtures/flight/config/webpackDevServer.config.js +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -90,6 +90,9 @@ module.exports = function(proxy, allowedHost) { | 90 | 90 | watchOptions: { | 91 | 91 | ignored: ignoredFiles(paths.appSrc), | 92 | 92 | }, | | 93 | + writeToDisk: filePath => { | | 94 | + return /react-client-manifest\.json$/.test(filePath); | | 95 | + }, | 93 | 96 | https: getHttpsConfig(), | 94 | 97 | host, | 95 | 98 | overlay: false, | |
Collapse file Copy file name to clipboardExpand all lines: fixtures/flight/server/handler.server.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -10,7 +10,7 @@ module.exports = function(req, res) { | 10 | 10 | import('../src/App.server.js').then(m => { | 11 | 11 | const dist = process.env.NODE_ENV === 'development' ? 'dist' : 'build'; | 12 | 12 | readFile( | 13 | | - resolve(__dirname, `../${dist}/react-transport-manifest.json`), | | 13 | + resolve(__dirname, `../${dist}/react-client-manifest.json`), | 14 | 14 | 'utf8', | 15 | 15 | (err, data) => { | 16 | 16 | if (err) { | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-transport-dom-webpack/src/ReactFlightWebpackPlugin.js +14-9Lines changed: 14 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 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 |
| |
|