From 491ed671b78952024927a06864761c4c8b15645e Mon Sep 17 00:00:00 2001 From: "andy.patterson" Date: Mon, 9 Jul 2018 13:54:46 -0400 Subject: [PATCH] perf: use rollup.js to bundle lib By using rollup we can support es module imports for other webpack and rollup users via the `package.json` `module` field. This allows for tree-shaking for this lib (especially for something like `MaybeT` which is not likely used very often). The other advantage to using rollup is some minor performance boosts and removal of circular import issues on the consumer. Currently using maybetyped in a repo with webpack or rollup results in warnings about circular imports. While this doesn't break anything, it is definitely sub-optimal to be the source of these warnings. --- .gitignore | 2 ++ package.json | 14 ++++++++++---- rollup.config.js | 11 +++++++++++ tsconfig.json | 5 ++--- 4 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 rollup.config.js diff --git a/.gitignore b/.gitignore index 17c696d..ce91edd 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ node_modules/ .vscode/ dist/ coverage/ + +.rpt2_cache diff --git a/package.json b/package.json index 671dcde..ea12fc2 100644 --- a/package.json +++ b/package.json @@ -2,15 +2,18 @@ "name": "maybetyped", "version": "0.0.0", "description": "Well-typed functional Maybe monad", - "main": "dist/src/index", - "types": "dist/src/index.d.ts", + "main": "dist/index.js", + "types": "dist/index.d.ts", + "module": "dist/index.mjs", "scripts": { "commitmsg": "commitlint -e $GIT_PARAMS", "lint": "tslint --config tslint.json --project . --format stylish", "test": "jest", + "rollup/cjs": "rollup --format cjs --config rollup.config.js --file dist/index.js", + "rollup/esm": "rollup --format esm --config rollup.config.js --file dist/index.mjs", "tsc": "tsc", - "prepush": "npm run -s lint && npm test", - "release": "rm -rf dist && npm run tsc && npx semantic-release" + "prepush": "run-s lint test", + "release": "rm -rf dist && run-s rollup/cjs rollup/esm && npx semantic-release" }, "repository": { "type": "git", @@ -56,6 +59,9 @@ "commitlint": "^7.0.0", "husky": "^0.14.3", "jest": "^22.4.3", + "npm-run-all": "^4.1.3", + "rollup": "^0.62.0", + "rollup-plugin-typescript2": "^0.15.1", "ts-jest": "^23.0.0", "ts-node": "^7.0.0", "tslint": "^5.9.1", diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 0000000..d8b139c --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,11 @@ +import typescript from 'rollup-plugin-typescript2'; + +export default { + input: './src/index.ts', + + plugins: [ + typescript({ + tsconfig: "tsconfig.json" + }) + ] +} diff --git a/tsconfig.json b/tsconfig.json index 174984d..ed2fe7f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,7 +6,7 @@ "strict": true, "noUnusedLocals": true, "moduleResolution": "node", - "module": "commonjs", + "module": "esnext", "target": "es5", "noImplicitAny": true, "noImplicitThis": true, @@ -19,8 +19,7 @@ ], }, "include": [ - "src/", - "tests" + "src/" ], "exclude": [ "node_modules"