forked from facebook/react
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Flight] Minimal webpack plugin (facebook#20228)
- Loading branch information
Showing
6 changed files
with
52 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
|
||
# production | ||
/build | ||
/dist | ||
|
||
# misc | ||
.DS_Store | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,20 @@ | ||
'use strict'; | ||
|
||
import {pipeToNodeWritable} from 'react-transport-dom-webpack/server'; | ||
import {readFileSync} from 'fs'; | ||
import {resolve} from 'path'; | ||
import * as React from 'react'; | ||
|
||
import url from 'url'; | ||
|
||
function resolve(path) { | ||
return url.pathToFileURL(require.resolve(path)).href; | ||
} | ||
|
||
module.exports = async function(req, res) { | ||
res.setHeader('Access-Control-Allow-Origin', '*'); | ||
const m = await import('../src/App.server.js'); | ||
// const m = require('../src/App.server.js'); | ||
const App = m.default.default || m.default; | ||
pipeToNodeWritable(<App />, res, { | ||
// TODO: Read from a map on the disk. | ||
[resolve('../src/Counter.client.js')]: { | ||
Counter: { | ||
id: './src/Counter.client.js', | ||
chunks: ['2'], | ||
name: 'Counter', | ||
}, | ||
}, | ||
[resolve('../src/Counter2.client.js')]: { | ||
Counter: { | ||
id: './src/Counter2.client.js', | ||
chunks: ['1'], | ||
name: 'Counter', | ||
}, | ||
}, | ||
[resolve('../src/ShowMore.client.js')]: { | ||
default: { | ||
id: './src/ShowMore.client.js', | ||
chunks: ['3'], | ||
name: 'default', | ||
}, | ||
'': { | ||
id: './src/ShowMore.client.js', | ||
chunks: ['3'], | ||
name: '', | ||
}, | ||
'*': { | ||
id: './src/ShowMore.client.js', | ||
chunks: ['3'], | ||
name: '*', | ||
}, | ||
}, | ||
}); | ||
res.setHeader('Access-Control-Allow-Origin', '*'); | ||
const moduleMap = JSON.parse( | ||
readFileSync( | ||
resolve(__dirname, '../dist/react-transport-manifest.json'), | ||
'utf8' | ||
) | ||
); | ||
pipeToNodeWritable(<App />, res, moduleMap); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters