Skip to content

Commit

Permalink
perf: use rollup.js to bundle lib
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
andy.patterson committed Jul 9, 2018
1 parent 5b3b52f commit 491ed67
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ node_modules/
.vscode/
dist/
coverage/

.rpt2_cache
14 changes: 10 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
11 changes: 11 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import typescript from 'rollup-plugin-typescript2';

export default {
input: './src/index.ts',

plugins: [
typescript({
tsconfig: "tsconfig.json"
})
]
}
5 changes: 2 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"strict": true,
"noUnusedLocals": true,
"moduleResolution": "node",
"module": "commonjs",
"module": "esnext",
"target": "es5",
"noImplicitAny": true,
"noImplicitThis": true,
Expand All @@ -19,8 +19,7 @@
],
},
"include": [
"src/",
"tests"
"src/"
],
"exclude": [
"node_modules"
Expand Down

0 comments on commit 491ed67

Please sign in to comment.