react-sketch icon indicating copy to clipboard operation
react-sketch copied to clipboard

jsdom bundled and required at runtime in browser

Open karlvr opened this issue 6 years ago • 2 comments

I am currently trying to resolve an issue where react-sketch causes jsdom to be included in my web app's webpack bundle. I can of course ignore jsdom using the webpack.IgnorePlugin however react-sketch also requires jsdom at runtime.

I am going to investigate this further.

karlvr avatar Jan 22 '19 19:01 karlvr

The reason jsdom is included in my web app is because the dist/index.js file from react-sketch includes a require('jsdom') in it.

The reason dist/index.js requires jsdom appears to be because jsdom is identified in the webpack externals by webpack/library.cfg.js in react-sketch.

I wonder if we're misusing externals (https://webpack.js.org/configuration/externals/) in react-sketch... I don't understand it well, but it seems externals should be used for our runtime dependencies that we don't want to include in our bundle—so the next user of our library will include them instead. In my case, it's my webpack which is processing react-sketch/dist/index.js and noticing the require('jsdom') and therefore bundling jsdom.

I don't think we need the externals generated from devDependencies in webpack/library.cfg.js at all. I'm going to experiment with a build like that and then make a PR if it works!

If you have any early feedback, I'd love to hear it.

karlvr avatar Jan 22 '19 20:01 karlvr

The size of the dist/index.js file is the same with that change: 332KB both ways.

karlvr avatar Jan 22 '19 20:01 karlvr