Nine Parsecs from Milwaukee

    @kenchan0130/babel-preset-google-apps-script

    0.7.2 • Public • Published

    npm version Build Status License: MIT

    babel-preset-google-apps-script

    Babel syntax preset for all Goolge Apps Script.

    Announcement

    If you are going to create a new Google Apps Script app with babel, I do not recommend using this preset.

    Google has announced support for V8 as the runtime engine for Google Apps Script. V8, Google Apps Script JavaScript runtime, supports the latest ECMAScript syntax, so you don't need to use this preset.

    Future plan

    Until the V8 runtime becomes stable, I will keep maintaining this project. And I will archive this repository when the time comes.

    Requiredment

    • Babel version 7

    Used plugins

    This preset includes the following plugins.

    ES3

    ES2015

    ES2016

    ES2018

    Installation

    Using npm:

    npm install --save-dev @kenchan0130/babel-preset-google-apps-script

    or using yarn:

    yarn add --dev @kenchan0130/babel-preset-google-apps-script

    Usage

    Via .babelrc (Recommended)

    .babelrc

    {
      "presets": ["@kenchan0130/babel-preset-google-apps-script"]
    }

    Via CLI

    babel --presets @kenchan0130/babel-preset-google-apps-script script.js

    Via Node API

    require("@babel/core").transform("code", {
      plugins: ["@kenchan0130/babel-preset-google-apps-script"]
    });

    Polyfill

    This library does not include polyfill. If you want to use it, I recommend using @babel/preset-env.

    Case webpack

    First, install the required dependencies for polyfill.

    npm i -D core-js/stable regenerator-runtime/runtime @babel/preset-env core-js@3

    And set webpack.config.js as follows.

    const path = require('path');
    const GasPlugin = require("gas-webpack-plugin"); // Define functions at the top level
    
    module.exports = {
      mode: 'none', // Prevent minify
      entry: [
        "core-js/stable",
        "regenerator-runtime/runtime",
        path.resolve(__dirname, 'src', 'index.js')
      ],
      output: {
        path: path.resolve(__dirname, 'dist'),
        filename: 'out.js',
      },
      module: {
        rules: [
          {
            test: /\.js$/,
            use: {
              loader: "babel-loader",
              query: {
                presets: [
                    [
                      "@babel/preset-env", {
                        useBuiltIns: "entry",
                        corejs: 3
                      }
                    ],
                    [
                      '@kenchan0130/babel-preset-google-apps-script'
                    ]
                ]
              }
            }
          }
        ]
      },
      plugins: [
        new GasPlugin()
      ]
    };

    References

    Development

    Test

    npm run test

    All you need to know is that the transforms are reflected.

    Release

    npm version major|minor|patch

    Run the command with local master branch.

    License

    MIT

    Install

    npm i @kenchan0130/babel-preset-google-apps-script

    DownloadsWeekly Downloads

    20

    Version

    0.7.2

    License

    MIT

    Unpacked Size

    14.3 kB

    Total Files

    4

    Last publish

    Collaborators

    • kenchan0130