Skip to content

Commit

Permalink
Use require.extensions to replace .client imports
Browse files Browse the repository at this point in the history
The simplest server doesn't need AOT compilation. Instead we can just
configure require.extensions. This is probably not the best idea to use
in prod but is enough to show the set up.
  • Loading branch information
sebmarkbage committed Nov 10, 2020
1 parent 0e37648 commit a11ad02
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions fixtures/flight/server/handler.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ module.exports = function(req, res) {
res.setHeader('Access-Control-Allow-Origin', '*');
pipeToNodeWritable(<App />, res, {
// TODO: Read from a map on the disk.
'./src/Counter.client.js': {
[require.resolve('../src/Counter.client.js')]: {
id: './src/Counter.client.js',
chunks: ['1'],
name: 'default',
},
'./src/ShowMore.client.js': {
[require.resolve('../src/ShowMore.client.js')]: {
id: './src/ShowMore.client.js',
chunks: ['2'],
name: 'default',
Expand Down
7 changes: 7 additions & 0 deletions fixtures/flight/server/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
'use strict';

require.extensions['.client.js'] = function(module, path) {
module.exports = {
$$typeof: Symbol.for('react.module.reference'),
name: path,
};
};

const babelRegister = require('@babel/register');

babelRegister({
Expand Down
11 changes: 2 additions & 9 deletions fixtures/flight/src/App.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,9 @@ import * as React from 'react';

import Container from './Container';

// TODO: A transform should read this from webpack plugin output.
const Counter = {
$$typeof: Symbol.for('react.module.reference'),
name: './src/Counter.client.js',
};
import Counter from './Counter.client';

const ShowMore = {
$$typeof: Symbol.for('react.module.reference'),
name: './src/ShowMore.client.js',
};
import ShowMore from './ShowMore.client';

export default function App() {
return (
Expand Down

0 comments on commit a11ad02

Please sign in to comment.