Skip to content

Update babel presets#220

Merged
lemonmade merged 2 commits intomasterfrom
improve-babel-presets
Oct 12, 2016
Merged

Update babel presets#220
lemonmade merged 2 commits intomasterfrom
improve-babel-presets

Conversation

@lemonmade
Copy link
Member

This PR updates how Shopify's Babel presets work. I know I kind of did this before and we decided not to separate them out so much, but I have some use cases where this makes sense and I feel like it is more in line with our linting configs.

Basically, it works like this:

  • There are separate configs for Node, Web, and React projects, where React is totally usable with either of the other two. The default config is just the web config.
  • The web config takes options, which it passes on to the es2015 preset. This allows us to use the {modules: false} option for our config, which makes the preset work with Rollup and Webpack 2 tree shaking.
  • The node option also takes options: modules (just like the web one), and version for specifying a desired version of Node. I was using a preset that just used process.version to check what plugins to add, but that didn't make sense since you usually develop in a more modern version of node than the one you build for. I just copied the logic into our own config so that you can manually specify the version.

I like this structure much better personally. It also enables things I've been working on: using Webpack 2 to do tree-shaked builds of both server and client bundles, both of which need the React transforms as well. The config just requires two lines instead of one for the client bundle, and the preset can actually be used for node without over-transforming stuff that doesn't need to be transformed:

// client
{
  presets: [
    ['shopify/web', {modules: false}],
    'shopify/react',
  ],
};

// server
{
  presets: [
    ['shopify/node', {modules: false}],
    'shopify/react',
  ],
};

cc/ @Shopify/javascript @bouk thoughts?


module.exports = function shopifyNodePreset(context, options) {
options = options || {};
var version = options.version || '5.7.0';
Copy link
Member Author

Choose a reason for hiding this comment

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

Note to self: probably just default to process.version.

Copy link
Contributor

Choose a reason for hiding this comment

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

yep, please do

require('babel-preset-stage-2'),
],
plugins: [
require('babel-plugin-transform-class-properties'),
Copy link
Member Author

Choose a reason for hiding this comment

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

Part of stage-2.

@lemonmade
Copy link
Member Author

Reping @Shopify/javascript — how do people feel about arranging the Babel presets in this way? Will this make our Babel preset usable by all projects you folks are currently working on? What can we do to make that happen, if the answer is no?

@bouk
Copy link
Contributor

bouk commented Oct 11, 2016

This makes sense. I'm OK with it as long as it's backwards-compatible

@nathanmarks
Copy link

LGTM from a marketing/growth perspective.

@lemonmade lemonmade merged commit e8052ff into master Oct 12, 2016
@lemonmade lemonmade deleted the improve-babel-presets branch October 12, 2016 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants