@kenchan0130/babel-preset-google-apps-script
v0.7.2
Published
Babel preset for all Goolge Apps Script.
Downloads
8
Maintainers
Readme
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
- @babel/plugin-transform-arrow-functions
- @babel/plugin-transform-block-scoped-functions
- @babel/plugin-transform-block-scoping
- @babel/plugin-transform-classes
- @babel/plugin-transform-computed-properties
- @babel/plugin-transform-destructuring
- @babel/plugin-transform-duplicate-keys
- @babel/plugin-transform-for-of
- @babel/plugin-transform-function-name
- @babel/plugin-transform-literals
- @babel/plugin-transform-object-super
- @babel/plugin-transform-parameters
- @babel/plugin-transform-shorthand-properties
- @babel/plugin-transform-spread
- @babel/plugin-transform-template-literals
- @babel/plugin-transform-unicode-regex
ES2016
ES2018
- @babel/plugin-proposal-object-rest-spread
- @babel/plugin-transform-dotall-regex
- @babel/plugin-proposal-unicode-property-regex
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
- https://github.com/eiel/babel-preset-google-apps-script
- Babel preset for Google Apps Script (not updated)
- Using legacy presets
- https://github.com/fossamagna/babel-preset-gas
- Babel preset for all Goolge Apps Script plugins
- Insufficient import of preset
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