From d22e80ac76cb6850fe1e4de81892860f7607f35b Mon Sep 17 00:00:00 2001 From: Navin Date: Wed, 30 Sep 2020 15:21:09 +0530 Subject: [PATCH] =?UTF-8?q?feat(build):=20=E2=9C=A8=20=20babel=20es=20&=20?= =?UTF-8?q?cjs=20build?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .babelrc.js | 37 +++++++++++++++++++++++++++++++++++++ .gitignore | 4 ++++ package.json | 10 ++++++++++ 3 files changed, 51 insertions(+) create mode 100644 .babelrc.js diff --git a/.babelrc.js b/.babelrc.js new file mode 100644 index 000000000..be1446e85 --- /dev/null +++ b/.babelrc.js @@ -0,0 +1,37 @@ +const { NODE_ENV, BABEL_ENV } = process.env; +const cjs = NODE_ENV === "test" || BABEL_ENV === "commonjs"; +const loose = true; + +module.exports = { + presets: [ + [ + "@babel/env", + { + loose, + modules: false, + exclude: ["@babel/plugin-transform-regenerator"], + }, + ], + "@babel/preset-typescript", + "@babel/react", + ], + plugins: [ + [ + "const-enum", + { + transform: "constObject", + }, + ], + "babel-plugin-transform-async-to-promises", + cjs && ["@babel/transform-modules-commonjs", { loose }], + [ + "@babel/transform-runtime", + { + useESModules: !cjs, + version: require("./package.json").dependencies[ + "@babel/runtime" + ].replace(/^[^0-9]*/, ""), + }, + ], + ].filter(Boolean), +}; diff --git a/.gitignore b/.gitignore index e325bc3d8..ea3b548d3 100644 --- a/.gitignore +++ b/.gitignore @@ -70,3 +70,7 @@ lerna-debug.log npm-debug.log* yarn-debug.log* yarn-error.log* + +#build +/es +/lib diff --git a/package.json b/package.json index 79246e962..1548dc3b8 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,8 @@ "author": "Timeless ", "scripts": { "build-storybook": "build-storybook", + "build:commonjs": "rm -rf ./lib && BABEL_ENV=commonjs babel --extensions .ts,.tsx --ignore ./src/**/*.test.tsx ./src --out-dir lib", + "build:es": "rm -rf ./es && babel --extensions .ts,.tsx --ignore ./src/**/*.test.tsx ./src --out-dir es", "commit": "gacp", "format": "prettier --write \"./**/*.{js,ts,css,less,json,md,html,yml,yaml,pcss,jsx,tsx}\"", "keys": "node scripts/build/keys", @@ -26,6 +28,7 @@ "test": "jest" }, "dependencies": { + "@babel/runtime": "^7.5.5", "@chakra-ui/counter": "1.0.0-rc.3", "@chakra-ui/hooks": "1.0.0-rc.3", "@chakra-ui/utils": "1.0.0-rc.3", @@ -45,7 +48,12 @@ "uuid": "8.3.0" }, "devDependencies": { + "@babel/cli": "^7.11.6", "@babel/core": "7.11.6", + "@babel/plugin-transform-runtime": "^7.11.5", + "@babel/preset-env": "^7.11.5", + "@babel/preset-react": "^7.10.4", + "@babel/preset-typescript": "^7.10.4", "@commitlint/cli": "11.0.0", "@commitlint/config-conventional": "11.0.0", "@storybook/addon-a11y": "6.0.21", @@ -69,6 +77,8 @@ "@typescript-eslint/parser": "4.1.1", "babel-eslint": "10.1.0", "babel-loader": "8.1.0", + "babel-plugin-const-enum": "^1.0.1", + "babel-plugin-transform-async-to-promises": "^0.8.15", "chalk": "4.1.0", "emotion": "10.0.27", "eslint": "7.9.0",