-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(module-loader): use standard package entry for node module loader (
#203) There is also a new demo for the commonjs module loader.
- Loading branch information
Showing
19 changed files
with
135 additions
and
24 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import {Card, Label} from '@blueprintjs/core'; | ||
import {ReactFeatureApp} from '@feature-hub/react'; | ||
import * as React from 'react'; | ||
|
||
export default { | ||
id: 'test:hello-world', | ||
|
||
create(): ReactFeatureApp { | ||
return { | ||
render: () => ( | ||
<Card style={{margin: '20px'}}> | ||
<Label>Hello, World!</Label> | ||
</Card> | ||
) | ||
}; | ||
} | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* @jest-environment puppeteer | ||
*/ | ||
|
||
import {Server} from 'http'; | ||
import {AddressInfo} from 'net'; | ||
import {Browser} from '../browser'; | ||
import {startServer} from '../start-server'; | ||
import renderMainHtml from './integrator.node'; | ||
import webpackConfigs from './webpack-config'; | ||
|
||
jest.setTimeout(60000); | ||
|
||
describe('integration test: "commonjs module loader"', () => { | ||
const browser = new Browser(5000); | ||
|
||
let server: Server; | ||
|
||
beforeAll(async () => { | ||
server = await startServer(webpackConfigs, renderMainHtml); | ||
|
||
const {port} = server.address() as AddressInfo; | ||
|
||
await browser.goto(`http://localhost:${port}`, 60000); | ||
}); | ||
|
||
afterAll(done => server.close(done)); | ||
|
||
it('loads the server-side rendered feature app HTML', async () => { | ||
await expect(page).toMatch('Hello, World!'); | ||
}); | ||
}); |
20 changes: 20 additions & 0 deletions
20
packages/demos/src/commonjs-module-loader/integrator.node.tsx
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import {FeatureAppManager, FeatureServiceRegistry} from '@feature-hub/core'; | ||
import {loadCommonJsModule} from '@feature-hub/module-loader/lib/node'; | ||
import {FeatureAppLoader} from '@feature-hub/react'; | ||
import * as React from 'react'; | ||
import * as ReactDOM from 'react-dom/server'; | ||
|
||
export default async function renderMainHtml(port: number): Promise<string> { | ||
const featureAppNodeUrl = `http://localhost:${port}/feature-app.commonjs.js`; | ||
const registry = new FeatureServiceRegistry(); | ||
|
||
const manager = new FeatureAppManager(registry, { | ||
moduleLoader: loadCommonJsModule | ||
}); | ||
|
||
await manager.preloadFeatureApp(featureAppNodeUrl); | ||
|
||
return ReactDOM.renderToString( | ||
<FeatureAppLoader manager={manager} src="" nodeSrc={featureAppNodeUrl} /> | ||
); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// tslint:disable-next-line:no-import-side-effect | ||
import '../blueprint-css'; |
24 changes: 24 additions & 0 deletions
24
packages/demos/src/commonjs-module-loader/webpack-config.ts
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import {join} from 'path'; | ||
import {Configuration} from 'webpack'; | ||
import {webpackBaseConfig} from '../webpack-base-config'; | ||
|
||
export default [ | ||
{ | ||
...webpackBaseConfig, | ||
entry: join(__dirname, './feature-app.tsx'), | ||
output: { | ||
filename: 'feature-app.commonjs.js', | ||
libraryTarget: 'commonjs2', | ||
publicPath: '/' | ||
}, | ||
target: 'node' | ||
}, | ||
{ | ||
...webpackBaseConfig, | ||
entry: join(__dirname, './integrator.ts'), | ||
output: { | ||
filename: 'integrator.js', | ||
publicPath: '/' | ||
} | ||
} | ||
] as Configuration[]; |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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