Skip to content

Support modified entry point #30

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

Merged
merged 3 commits into from
May 29, 2018
Merged

Support modified entry point #30

merged 3 commits into from
May 29, 2018

Conversation

roborourke
Copy link
Contributor

Fixes #29

const hotClientIndex = config.entry.indexOf( hotClient );
config.entry.splice(hotClientIndex, 1, require.resolve( '../overrides/webpackHotDevClient' ) );

if ( config.entry instanceof Array ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a hint that the modern way of doing this is Array.isArray( config.entry ). While irrelevant here, this is also faster with modern browsers.

config.entry.splice( hotClientIndex, 1, require.resolve( '../overrides/webpackHotDevClient' ) );
}

if ( config.entry instanceof Object ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be an else if, right?

Copy link
Contributor Author

@roborourke roborourke May 29, 2018

Choose a reason for hiding this comment

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

Yeah I had it as that but had forgotten Arrays are objects too, thought instanceof gave a more scoped result

Object.keys( config.entry ).forEach( key => {
const entry = config.entry[key];

if ( entry instanceof String && entry === hotClient ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the extra type check when using === anyway?

}

if ( config.entry instanceof Object ) {
Object.keys( config.entry ).forEach( key => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like it should be Object.entries.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sometimes forget about node environment vs web! Thought Object.entries was still experimental so I've not made a habit of using it

config.entry[key] = require.resolve( '../overrides/webpackHotDevClient' );
}

if ( entry instanceof Array ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Again else if, and Array.isArray.


if ( config.entry instanceof Array ) {
const hotClientIndex = config.entry.indexOf( hotClient );
config.entry.splice( hotClientIndex, 1, require.resolve( '../overrides/webpackHotDevClient' ) );
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 check for >= 0 here? Like below in the forEach...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy paste from the original code, but makes sense while we're making things robust

@roborourke
Copy link
Contributor Author

@tfrommen ace review thanks :) Will make those updates asap

@rmccue
Copy link
Member

rmccue commented May 29, 2018

(Note that like create-react-app, you should aim for Node v8 compatibility, so some of these might not be available.)

@tfrommen
Copy link
Contributor

@rmccue not sure what version we need/want to support, but according to https://node.green/, both Object.entries() and Array.isArray() are supported since Node v8.2, which is just the oldest they have on that website.

config.entry.splice( hotClientIndex, 1, require.resolve( '../overrides/webpackHotDevClient' ) );
}
} else if ( config.entry instanceof Object ) {
Object.entries( config.entry ).forEach( ( key, entry ) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs to be ( [ key, entry ] ) => {.

config.entry[key] = require.resolve( '../overrides/webpackHotDevClient' );
}

if ( Array.isArray( entry ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

else if

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think it strictly needs to be an else if, it won't affect the behaviour there. I usually find this style a bit more readable

@roborourke
Copy link
Contributor Author

Ha, I'd just found that same site. Pretty handy reference

Copy link
Contributor

@tfrommen tfrommen left a comment

Choose a reason for hiding this comment

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

Cool. 😎

@roborourke roborourke merged commit 88d2cda into master May 29, 2018
@roborourke roborourke deleted the rewired-entry-support branch May 29, 2018 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants