Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Bug fix: Respect externals options in library plugin #999

Closed
wants to merge 1 commit into from
Closed

Bug fix: Respect externals options in library plugin #999

wants to merge 1 commit into from

Conversation

sloria
Copy link

@sloria sloria commented Jul 17, 2018

Previously, externals was ignored. This passes along
the options to webpack-node-externals.

Fixes #987

I verified that this fix in a project I was working on. Without this change, externals.whitelist had no effect. With this change, whitelisted modules get bundled into the output file.

Copy link
Member

@edmorley edmorley left a comment

Choose a reason for hiding this comment

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

Hi! Thank you for the PR :-)

@@ -56,7 +56,7 @@ module.exports = (neutrino, opts = {}) => {
neutrino.config
.when(hasSourceMap, () => neutrino.use(banner))
.devtool('source-map')
.externals([nodeExternals()])
.externals([nodeExternals(options.externals)])
Copy link
Member

@edmorley edmorley Jul 26, 2018

Choose a reason for hiding this comment

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

options.externals isn't defined by default, so this will be calling nodeExternals(undefined). This is currently handled ok, due to:
https://github.com/liady/webpack-node-externals/blob/cfa1c5b33752fb8cb72360167ae89b23816cdefe/index.js#L22

...however it doesn't feel right to be relying on an implementation detail that they could possibly change in a minor version.

As such, perhaps the implementation should copy what @neutrinojs/react-components does? (With optional cleanup there, since the current opts.externals !== false && {} appears overly complex, unless I'm mis-remembering how deepmerge handles merging different data types.)

Copy link
Member

Choose a reason for hiding this comment

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

Thank you for updating the PR - it's missing the .when() of the react-components implementation though?
https://github.com/mozilla-neutrino/neutrino-dev/blob/ed21fa6074354609389710f051286356b073cb4e/packages/react-components/index.js#L53

Previously, externals was ignored. This passes along
the options to webpack-node-externals.

Fixes #987
@sloria
Copy link
Author

sloria commented Jul 29, 2018

OK, I've gone ahead and updated the code to use the same logic that react-components is using. Let me know if there's anything else that needs to be done before this is merged.

@edmorley
Copy link
Member

edmorley commented Aug 1, 2018

Hi! Travis is failing due to an unrelated Jest/JSDom regression (jestjs/jest#6766). We're holding off merging any more things to master until it's resolved.

@sloria
Copy link
Author

sloria commented Aug 1, 2018

@edmorley OK. I ran into that Jest issue in some of my projects. The fix is to set the environment, like so:

  "jest": {
    "testEnvironment": "node"
  },

@edmorley
Copy link
Member

edmorley commented Aug 1, 2018

Whilst that would work around the issue, it seems like this should be fixed in Jest, so once they do so, we'd want to remove the workaround again anyway.

@sloria
Copy link
Author

sloria commented Aug 1, 2018

I understand. But shouldn't neutrino override "testEnvironment" anyway? Jest's default is to run against jsdom.

https://github.com/facebook/jest/blob/fb2a6ac4d3f4e9530941e24030b52f3d506aa2de/packages/jest-config/src/defaults.js#L66

@edmorley
Copy link
Member

I understand. But shouldn't neutrino override "testEnvironment" anyway? Jest's default is to run against jsdom.

Ah good point! So the default of 'jsdom' is fine for the browser-targetting Neutrino presets, but perhaps not what is wanted for @neutrinojs/node etc. I've filed #1020 for this.

In the meantime, a new Jest minor version has been released, which fixes the test failures - I've retriggered and Travis is now green :-)

@@ -56,7 +56,7 @@ module.exports = (neutrino, opts = {}) => {
neutrino.config
.when(hasSourceMap, () => neutrino.use(banner))
.devtool('source-map')
.externals([nodeExternals()])
.externals([nodeExternals(options.externals)])
Copy link
Member

Choose a reason for hiding this comment

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

Thank you for updating the PR - it's missing the .when() of the react-components implementation though?
https://github.com/mozilla-neutrino/neutrino-dev/blob/ed21fa6074354609389710f051286356b073cb4e/packages/react-components/index.js#L53

@edmorley edmorley added the bug label Aug 15, 2018
@eliperelman eliperelman reopened this Aug 23, 2018
@sloria
Copy link
Author

sloria commented Aug 23, 2018

@edmorley Sorry for the delay in my response. I'm not able to work on this more right now, as I'm no longer using neutrino.

I'd be happy if someone else brought this one home.

@eliperelman
Copy link
Member

Continuing in #1040, thank you so much for your help here!

@sloria sloria deleted the fix-externals-options branch August 23, 2018 19:40
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging this pull request may close these issues.

@neutrinojs/library: the externals options is ignored
3 participants