Skip to content

Commit

Permalink
Configure Babel proposal plugins via Gatsby Node API
Browse files Browse the repository at this point in the history
Configured the installed Babel proposal plugins through Gatsby's Node
API (1) using the provided `setBabelPlugin` action (2).

References:

  (1) https://www.gatsbyjs.org/docs/node-apis
  (2) https://www.gatsbyjs.org/docs/actions

GH-29
  • Loading branch information
arcticicestudio committed Nov 19, 2018
1 parent beee8b6 commit 9e8aea6
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
85 changes: 85 additions & 0 deletions .gatsby/onCreateBabelConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Copyright (C) 2018-present Arctic Ice Studio <[email protected]>
* Copyright (C) 2018-present Sven Greb <[email protected]>
*
* Project: Nord Docs
* Repository: https://github.com/arcticicestudio/nord-docs
* License: MIT
*/

/**
* @file Implementation of the Gatsby Node `onCreateBabelConfig` API.
* Allows to let plugins extend/mutate the project's Babel configuration.
* @author Arctic Ice Studio <[email protected]>
* @author Sven Greb <[email protected]>
* @see https://gatsbyjs.org/docs/node-apis/#onCreateBabelConfig
* @see https://babeljs.io
* @since 0.1.0
*/

/**
* Implementation of the Gatsby Node `onCreateBabelConfig` API.
*
* @method onCreateBabelConfig
* @param {object} actions Collection functions provided by Gatsby used to manipulate the state of the build process.
* @see https://gatsbyjs.org/docs/node-apis/#onCreateBabelConfig
* @see https://gatsbyjs.org/docs/actions
* @since 0.1.0
*/
const onCreateBabelConfig = ({ actions }) => {
/*
* Allows to use the "ES Class Fields & Static Properties" proposal to transforms static class properties as well as
* properties declared with the experimental property initializer syntax.
*
* References:
* - https://github.com/tc39/proposal-class-fields
* - https://babeljs.io/docs/en/babel-plugin-proposal-class-properties
*/
actions.setBabelPlugin({
name: "@babel/plugin-proposal-class-properties",
options: {
loose: true
}
});

/*
* Allows to use the experimental `export { default} from "mod"` proposal syntax.
*
* References:
* - https://github.com/tc39/proposal-export-default-from
* - https://babeljs.io/docs/en/babel-plugin-proposal-export-default-from
*/
actions.setBabelPlugin({ name: "@babel/plugin-proposal-export-default-from" });

/*
* Allows to use the "Nullish Coalescing" proposal trhough the experimental `??` operator to combine with the
* "Optional Chaining" proposal operator.
*
* References:
* - https://github.com/tc39/proposal-nullish-coalescing
* - https://babeljs.io/docs/en/babel-plugin-proposal-nullish-coalescing-operator
*/
actions.setBabelPlugin({
name: "@babel/plugin-proposal-nullish-coalescing-operator",
options: {
loose: false
}
});

/*
* Allows to use the "Optional Chaining" proposal through the experimental `?.` operator in combination with the
* "Nullish Coalescing" proposal operator.
*
* References:
* - https://github.com/tc39/proposal-optional-chaining
* - https://babeljs.io/docs/en/babel-plugin-proposal-optional-chaining
*/
actions.setBabelPlugin({
name: "@babel/plugin-proposal-optional-chaining",
options: {
loose: false
}
});
};

module.exports = onCreateBabelConfig;
17 changes: 17 additions & 0 deletions gatsby-node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright (C) 2018-present Arctic Ice Studio <[email protected]>
* Copyright (C) 2018-present Sven Greb <[email protected]>
*
* Project: Nord Docs
* Repository: https://github.com/arcticicestudio/nord-docs
* License: MIT
*/

/**
* @file Implementation of Gatsby Node APIs.
* @author Arctic Ice Studio <[email protected]>
* @author Sven Greb <[email protected]>
* @see https://gatsbyjs.org/docs/node-apis
*/

exports.onCreateBabelConfig = require("./.gatsby/onCreateBabelConfig");

0 comments on commit 9e8aea6

Please sign in to comment.