Skip to content

Commit

Permalink
Merge pull request #63 from timelessco/build-tools
Browse files Browse the repository at this point in the history
Build tools
  • Loading branch information
navin-moorthy authored Sep 30, 2020
2 parents 05dab57 + 72f83c2 commit de01ee0
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 2 deletions.
31 changes: 31 additions & 0 deletions .babelrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
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: [
cjs && ["@babel/plugin-transform-modules-commonjs", { loose }],
[
"@babel/transform-runtime",
{
useESModules: !cjs,
version: require("./package.json").dependencies[
"@babel/runtime"
].replace(/^[^0-9]*/, ""),
},
],
].filter(Boolean),
ignore: ["**/*/__tests__", "**/*/stories"],
};
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,8 @@ lerna-debug.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

#buildsize
size-plugin.json
stats-react.json
stats.html
39 changes: 38 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,31 @@
},
"license": "MIT",
"author": "Timeless <hello@timeless.co>",
"main": "dist/lib/index.js",
"unpkg": "dist/umd/renderless-components.min.js",
"module": "dist/es/index.js",
"types": "dist/types/index.d.ts",
"files": [
"dist"
],
"scripts": {
"build": "concurrently \"yarn build:commonjs\" \"yarn build:es\" \"yarn build:types\" \"yarn build:umd\"",
"build-storybook": "build-storybook",
"build:commonjs": "rimraf ./dist/lib && cross-env BABEL_ENV=commonjs babel --extensions .ts,.tsx ./src --out-dir dist/lib",
"build:es": "rimraf ./dist/es && babel --extensions .ts,.tsx ./src --out-dir dist/es",
"build:types": "rimraf ./dist/types && tsc --emitDeclarationOnly",
"build:umd": "rimraf ./dist && cross-env NODE_ENV=production rollup -c && rollup-plugin-visualizer stats-react.json",
"commit": "gacp",
"format": "prettier --write \"./**/*.{js,ts,css,less,json,md,html,yml,yaml,pcss,jsx,tsx}\"",
"keys": "node scripts/build/keys",
"lint": "eslint . --ext .tsx,.ts,.jsx,.js --fix",
"lint:package": "sort-package-json",
"stats": "open ./stats.html",
"storybook": "start-storybook -p 6006",
"test": "jest"
},
"dependencies": {
"@babel/runtime": "^7.11.2",
"@chakra-ui/counter": "1.0.0-rc.4",
"@chakra-ui/hooks": "1.0.0-rc.4",
"@chakra-ui/utils": "1.0.0-rc.4",
Expand All @@ -44,9 +58,16 @@
"uuid": "8.3.0"
},
"devDependencies": {
"@babel/cli": "^7.11.6",
"@babel/core": "7.11.6",
"@babel/plugin-transform-modules-commonjs": "^7.10.4",
"@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",
"@rollup/plugin-replace": "^2.3.3",
"@storybook/addon-a11y": "6.0.22",
"@storybook/addon-actions": "6.0.22",
"@storybook/addon-essentials": "6.0.22",
Expand All @@ -69,6 +90,8 @@
"babel-eslint": "10.1.0",
"babel-loader": "8.1.0",
"chalk": "4.1.0",
"concurrently": "^5.3.0",
"cross-env": "^7.0.2",
"emotion": "10.0.27",
"eslint": "7.10.0",
"eslint-config-prettier": "6.12.0",
Expand All @@ -95,9 +118,23 @@
"react-test-renderer": "16.13.1",
"react-transition-group": "4.4.1",
"reakit-test-utils": "0.14.5",
"rimraf": "^3.0.2",
"rollup": "^2.28.2",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-peer-deps-external": "^2.2.3",
"rollup-plugin-size": "^0.2.2",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-visualizer": "^4.1.1",
"sort-package-json": "1.46.0",
"ts-jest": "26.4.1",
"ts-morph": "8.1.1",
"typescript": "4.0.3"
}
},
"peerDependencies": {
"react": "^16.8.0",
"react-dom": "^16.8.0"
},
"main:umd": "dist/umd/renderless-components.js"
}
66 changes: 66 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import babel from "rollup-plugin-babel";
import { terser } from "rollup-plugin-terser";
import size from "rollup-plugin-size";
import externalDeps from "rollup-plugin-peer-deps-external";
import resolve from "rollup-plugin-node-resolve";
import commonJS from "rollup-plugin-commonjs";
import visualizer from "rollup-plugin-visualizer";
import replace from "@rollup/plugin-replace";

const external = ["react", "react-dom"];

const globals = {
react: "React",
"react-dom": "ReactDOM",
};

const inputSrc = "src/index.ts";

const extensions = [".js", ".jsx", ".es6", ".es", ".mjs", ".ts", ".tsx"];
const babelConfig = { extensions, runtimeHelpers: true };
const resolveConfig = { extensions, preferBuiltins: true };

export default [
{
input: inputSrc,
output: {
name: "Renderless Components",
file: "dist/umd/renderless-components.js",
format: "umd",
sourcemap: true,
globals,
},
external,
plugins: [
replace({ "process.env.NODE_ENV": `"production"`, delimiters: ["", ""] }),
resolve(resolveConfig),
babel(babelConfig),
commonJS(),
externalDeps(),
],
},
{
input: inputSrc,
output: {
name: "Renderless Components",
file: "dist/umd/renderless-components.min.js",
format: "umd",
sourcemap: true,
globals,
},
external,
plugins: [
replace({ "process.env.NODE_ENV": `"production"`, delimiters: ["", ""] }),
resolve(resolveConfig),
babel(babelConfig),
commonJS(),
externalDeps(),
terser(),
size(),
visualizer({
filename: "stats-react.json",
json: true,
}),
],
},
];
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"module": "esnext",
"lib": ["dom", "esnext"],
"declaration": true,
"declarationDir": "dist/types",
"sourceMap": true,
"moduleResolution": "node",
"skipLibCheck": true,
Expand All @@ -21,5 +22,5 @@
"resolveJsonModule": true,
"types": ["node", "jest", "@testing-library/jest-dom"]
},
"exclude": ["node_modules"]
"exclude": ["node_modules", "dist", "**/*/stories", "**/*/__tests__"]
}

0 comments on commit de01ee0

Please sign in to comment.