babel-plugin-dev-expression icon indicating copy to clipboard operation
babel-plugin-dev-expression copied to clipboard

wrap the import?

Open oliviertassinari opened this issue 9 years ago • 2 comments

I'm wondering if it would aslo make sens to let the plugin wrap the import/require of the warning dependency with a process.env.NODE_ENV !== 'production' block.

That shouldn't make any different when using a flat bundler like rollup but I think that would save us some module tree traversal when using a bundler like webpack.

oliviertassinari avatar Aug 23 '16 10:08 oliviertassinari

Could work. Right now this is a literal copy/paste of https://github.com/facebook/fbjs/blob/master/packages/babel-preset-fbjs/plugins/dev-expression.js. That would take it away a bit.

It wouldn't necessarily be 100% maybe? e.g. I use it for https://github.com/reactjs/react-router/blob/8707d05b00273590e4d054771b8ae7ae9ad312e3/modules/RoutingContext.js#L3. But maybe that doesn't matter.

taion avatar Aug 23 '16 14:08 taion

There's one catch to this proposal: wrapping an import is not valid ES6 and will cause babel to complain as such:

'import' and 'export' may only appear at the top level

However, I don't see harm in making it an option.

anilanar avatar Feb 13 '17 12:02 anilanar