Skip to content
This repository has been archived by the owner on Apr 21, 2022. It is now read-only.

plugin-build-node: need a way to configure babel compilation #25

Open
taras opened this issue Mar 13, 2019 · 4 comments
Open

plugin-build-node: need a way to configure babel compilation #25

taras opened this issue Mar 13, 2019 · 4 comments

Comments

@taras
Copy link

taras commented Mar 13, 2019

Currently, there is no way to configure how Babel compiles source which makes it impossible to add plugins like @babel/plugin-proposal-class-properties or change how @babel/preset-env compiles the source.

As a library maintainer, I need a way to configure the compilation for my project. If you're open to changing this, I can create a PR to add this functionality.

@FredKSchott
Copy link
Owner

Hi @taras, thanks for your patience. You should be able to configure the Babel compilation with a normal top-level .babelrc (or similar) configuration file in your project. @pika/plugin-standard-pkg will use this to convert any experimental language features that you use into standard, ES2018 JavaScript. @pika/plugin-build-node then builds off of that plugin's standard output.

Does that help answer your question? tl;dr: A top-level .babelrc file should do the trick.

@taras
Copy link
Author

taras commented Mar 25, 2019

Hi @FredKSchott, thank you for taking the time to get back to me. If I understand correctly, the idea is that @pika/plugin-standard-pkg will use .babelrc to transpile to ES2018 features and @pika/plugin-build-node will pickup from there.

In my situation, I want to configure the build to be slightly different for Node than browser or ES builds. Our current build process uses Rollup directly and we specify based on build target how we want it to build the dist files.

We make an assumption that our CJS builds will be used in Node where class syntax is widely supported so we don't transpile classes in CJS. For ES builds, we assume these will likely be consumed by Webpack, where node_modules are often excluded, which means that our ES builds have to target down to browsers that don't support the class syntax.

We find ourselves doing this kind of fuckery because Babel doesn't support extending native classes which leads to transpiling all classes or none at all.

How can I customize babel transpilation for Node differently than other distributions?

@FredKSchott
Copy link
Owner

Hahaha fair enough, thanks for clarifying. Check out the “minNodeVersion” in the plugin README. Could that fit your need here?

Although class syntax is supported all the way back to Node.v6, so im surprised to hear that this is happening. Are you seeing classes getting compiled out in your build output?

@taras
Copy link
Author

taras commented Mar 25, 2019

You are correct in that Node should not be transpiling class syntax because the default minNodeVersion is 6. I had @babe/preset-env in my .babelrc which caused everything to get compiled by @pika/plugin-standard-pkg. I removed it and now node build doesn't transpile class syntax.

How do I get @pika/plugin-build-web to transpile class syntax to use with Babel?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants