-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1632: feat(webpack): introduce experimental esbuild transpilation r=jhiode a=jhiode To test this just add `esbuild` and `esbuild-loader` as dependencies to `hops-template-redux`. ``` $ time -l yarn hops build -p hops-template-react:info running 'build' in 'production' mode hops-template-react:info bundling 'node' finished after 5.6s (2.93 MB) - server.js (2.93 MB) hops-template-react:info bundling 'build' finished after 12.9s (318 kB) - hops-template-react-1-71d927b348e8.js (279 kB) - hops-template-react-4531ec959528.js (38.2 kB) - main-e94a689b8054.css (207 B) ✨ Done in 17.02s. ``` ``` $ time -l yarn hops build -p --experimentalEsbuild hops-template-react:info running 'build' in 'production' mode hops-template-react:info bundling 'node' finished after 4.2s (2.59 MB) - server.js (2.59 MB) hops-template-react:info bundling 'build' finished after 4s (223 kB) - hops-template-react-1-89661b912d7e.js (211 kB) - hops-template-react-202879a799d9.js (11.7 kB) - main-e94a689b8054.css (207 B) ✨ Done in 8.63s. ``` Memory consumption also goes down from ~340MB to ~240MB. Co-authored-by: Jonas Holland <[email protected]>
- Loading branch information
Showing
50 changed files
with
382 additions
and
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// eslint-disable-next-line node/no-extraneous-require | ||
const { createTransformer } = require('esbuild-jest'); | ||
|
||
const transformer = createTransformer({ | ||
sourcemap: true, | ||
}); | ||
|
||
module.exports = { | ||
process(content, filename, config, opts) { | ||
content = content.replace( | ||
/importComponent\s*\(\s*\(\)\s+=>\s+import\(\s*'([^']+)'\s*\)\s*\)/g, | ||
"importComponent({ component: require('$1') })" | ||
); | ||
|
||
return transformer.process(content, filename, config, opts); | ||
}, | ||
}; |
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
10 changes: 10 additions & 0 deletions
10
packages/react/import-component/import-component-loader.js
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,10 @@ | ||
const regex = /importComponent\s*\(\s*\(\)\s+=>\s+import\(\s*'([^']+)'\s*\)\s*\)/g; | ||
|
||
function importComponentLoader(source) { | ||
return source.replace( | ||
regex, | ||
"importComponent({ load: () => import('$1'), moduleId: require.resolveWeak('$1') })" | ||
); | ||
} | ||
|
||
module.exports = importComponentLoader; |
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
28 changes: 28 additions & 0 deletions
28
packages/spec/integration/esbuild-typescript/__tests__/develop.js
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,28 @@ | ||
const { handleConsoleOutput } = require('../../../helpers'); | ||
|
||
describe('typescript development server', () => { | ||
let url; | ||
|
||
beforeAll(async () => { | ||
const { getUrl } = HopsCLI.start('--fast-dev', '--experimental-esbuild'); | ||
url = await getUrl(); | ||
}); | ||
|
||
it('renders a simple jsx site', async () => { | ||
const { page } = await createPage(); | ||
page.on('console', (msg) => handleConsoleOutput(msg)); | ||
await page.goto(url); | ||
expect(await page.content()).toMatch('<h1>test</h1>'); | ||
|
||
await page.close(); | ||
}); | ||
|
||
it('supports code-splitting', async () => { | ||
const { page } = await createPage(); | ||
page.on('console', (msg) => handleConsoleOutput(msg)); | ||
await page.goto(url); | ||
expect(await page.content()).toMatch('<p>lorem ipsum.</p>'); | ||
|
||
await page.close(); | ||
}); | ||
}); |
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,3 @@ | ||
import * as React from 'react'; | ||
|
||
export default () => <p>lorem ipsum.</p>; |
File renamed without changes.
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 { render, importComponent } from 'hops'; | ||
import * as React from 'react'; | ||
import { Helmet } from 'react-helmet-async'; | ||
|
||
import Headline from './headline'; | ||
|
||
const Content = importComponent(() => import('./content')); | ||
|
||
export default render( | ||
<> | ||
<Helmet> | ||
<link rel="icon" href="data:;base64,iVBORw0KGgo=" /> | ||
</Helmet> | ||
<Headline /> | ||
<Content /> | ||
</> | ||
); |
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 @@ | ||
{ | ||
"name": "fixture-esbuild-typescript", | ||
"version": "1.0.0", | ||
"private": true, | ||
"engines": { | ||
"node": "12 || 14 || 15" | ||
}, | ||
"jest": { | ||
"displayName": "integration", | ||
"testEnvironment": "jest-environment-hops", | ||
"setupFilesAfterEnv": [ | ||
"../../jest.setup.js" | ||
] | ||
}, | ||
"hops": { | ||
"gracePeriod": 0 | ||
}, | ||
"scripts": { | ||
"start": "hops start --experimental-esbuild", | ||
"build": "hops build --experimental-esbuild" | ||
}, | ||
"dependencies": { | ||
"esbuild": "*", | ||
"esbuild-jest": "*", | ||
"esbuild-loader": "*", | ||
"hops": "*", | ||
"hops-typescript": "*", | ||
"react": "*", | ||
"react-helmet-async": "*", | ||
"typescript": "*" | ||
} | ||
} |
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,3 @@ | ||
{ | ||
"extends": "hops-typescript/tsconfig.json" | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions
5
packages/spec/integration/typescript-unit-testing/headline.jsx
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,5 @@ | ||
import React from 'react'; | ||
|
||
const Headline = () => <h1>test</h1>; | ||
|
||
export default Headline; |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...late-redux/src/counter/spec/index.spec.js → ...ate-redux/src/counter/spec/index.spec.jsx
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
Oops, something went wrong.