From 9e54d8813d33de7e2eb0c101ebb3797a06143cf9 Mon Sep 17 00:00:00 2001 From: Tetsuharu OHZEKI Date: Mon, 5 Sep 2016 00:29:34 +0900 Subject: [PATCH] build(rollup): enable babel transform --- package.json | 2 ++ rollup.config.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/package.json b/package.json index 9f63c8d1..5f904dd3 100644 --- a/package.json +++ b/package.json @@ -79,6 +79,7 @@ "babel-cli": "^6.14.0", "babel-core": "^6.14.0", "babel-loader": "^6.2.5", + "babel-plugin-external-helpers": "^6.8.0", "babel-plugin-transform-es2015-modules-commonjs": "^6.14.0", "babel-plugin-transform-inline-environment-variables": "^6.8.0", "babel-plugin-transform-node-env-inline": "^6.8.0", @@ -103,6 +104,7 @@ "postcss-custom-properties": "^5.0.1", "postcss-import": "^8.1.2", "rollup": "^0.35.14", + "rollup-plugin-babel": "^2.6.1", "rollup-plugin-commonjs": "^5.0.3", "rollup-plugin-node-resolve": "^2.0.0", "stylelint": "^7.2.0", diff --git a/rollup.config.js b/rollup.config.js index e2a3ac95..4a50c164 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -6,6 +6,7 @@ const path = require('path'); const nodeResolve = require('rollup-plugin-node-resolve'); const commonjs = require('rollup-plugin-commonjs'); +const babel = require('rollup-plugin-babel'); const isRelease = process.env.NODE_ENV === 'production'; @@ -15,6 +16,42 @@ assert.ok(!!KAREN_ENTRY_POINT, 'not found process.env.KAREN_ENTRY_POINT'); const KAREN_CLIENT_DIST_DIR = process.env.KAREN_CLIENT_DIST_DIR; assert.ok(!!KAREN_CLIENT_DIST_DIR, 'not found process.env.KAREN_CLIENT_DIST_DIR'); +const babelPresets = [ +]; + +let babelPlugins = [ + // For our target browsers, we need not some transforms. + + // es2016 level + 'babel-plugin-transform-exponentiation-operator', + // es2017 level + 'babel-plugin-syntax-trailing-function-commas', + 'babel-plugin-transform-async-to-generator', + + // for React + 'syntax-jsx', + 'transform-react-jsx', + + // some utilitis + 'transform-inline-environment-variables', + 'transform-node-env-inline', + + // to remove duplicated helper methods inserted by babel. + 'external-helpers', +]; + +if (isRelease) { + babelPlugins = babelPlugins.concat([ + 'transform-react-constant-elements', + 'transform-react-inline-elements', + ]); +} +else { + babelPlugins = babelPlugins.concat([ + 'transform-react-jsx-source', + ]); +} + // https://github.com/rollup/rollup/wiki/JavaScript-API // https://github.com/rollup/rollup/wiki/Command-Line-Interface module.exports = { @@ -43,5 +80,12 @@ module.exports = { commonjs({ ignoreGlobal: true, }), + + // https://github.com/rollup/rollup-plugin-babel + babel({ + exclude: 'node_modules/**', + presets: babelPresets, + plugins: babelPlugins, + }), ] };