plasticine / inject-loader

πŸ’‰πŸ“¦ A Webpack loader for injecting code into modules via their dependencies.
https://www.npmjs.com/package/inject-loader
MIT License
482 stars 47 forks source link

set compact to false and provide filename to babel #38

Closed seanparmelee closed 7 years ago

seanparmelee commented 7 years ago

First off, thank you for all your hard work on this loader; it's been a lifesaver during our requirejs -> webpack transition!

I just started instrumenting my code with babel-plugin-istanbul and I started receiving these warnings:

[BABEL] Note: The code generator has deoptimised the styling of "unknown" as it exceeds the max of "500KB".

I tracked it back to when I use inject-loader on one of our larger modules (which is now even larger as it includes the code coverage instrumentation). By default, the compact option is set to auto:

Do not include superfluous whitespace characters and line terminators. When set to "auto" compact is set to true on input sizes of >500KB.

I'd like to explicitly set this option to something other than auto. Right now, this PR sets it to false to reflect how this behaves the majority of the time (assuming most people aren't using inject-loader on >500KB files). true works as well and it would mean there's less work for babel to do when it transforms the AST back into code.

Aside from the compact option, I also added the filename option to assist in debugging Babel messages like the one I encountered (without the filename, it falls back to "unknown"). Adding filename means we also have to set babelrc: false to prevent it from trying to look up an external config file (which can interfere with inject-loader).

vladimir-tikhonov commented 7 years ago

lgtm πŸ‘

plasticine commented 7 years ago

Thanks very much for this @seanparmelee πŸ‘