Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use babel node for local development to support ES6 import #1278

Merged
merged 5 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion packages/pwa-kit-dev/bin/pwa-kit-dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,16 @@ const main = async () => {
)
.addOption(new program.Option('--noHMR', 'disable the client-side hot module replacement'))
.action(async ({inspect, noHMR}) => {
execSync(`node${inspect ? ' --inspect' : ''} ${resolvedSSRPath}`, {
// We use @babel/node instead of node because we want to support ES6 import syntax
const babelNode = p.join(
require.resolve('webpack'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why webpack rather than babel-node itself?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because for some reason, babel packages have weird namings, i think babel node was called babel-node and since a major version (i forgot exactly which version), they moved to scoped packages like @babel/node.

However, require.resolve doesn't work for both babel-node nor @babel/node, so i had to fall back to webpack...

I also don't understand why all pwa-kit-dev commands resolves to bin using path.join('..','..','..'), but i just followed the existing pattern...

if anyone knows the reason, pls let me know.

'..',
'..',
'..',
'.bin',
'babel-node'
)
execSync(`${babelNode} ${inspect ? '--inspect' : ''} ${resolvedSSRPath}`, {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just npx babel-node?

Copy link
Collaborator Author

@kevinxh kevinxh Jun 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think require.resolve finds the binaries from pwa-kit-dev correctly, and that causes a delay for the start command when you run it the first time, cuz npx will try to install it...

env: {
...process.env,
...(noHMR ? {HMR: 'false'} : {})
Expand Down
Loading