Last active
May 14, 2021 07:00
-
-
Save jasonsturges/408bb65155c04b671eb1f3f3d95c244d to your computer and use it in GitHub Desktop.
Creating a TypeScript NPM Package
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node_modules | |
build | |
dist | |
docs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"projectFolder": ".", | |
"mainEntryPointFilePath": "<projectFolder>/build/index.d.ts", | |
"bundledPackages": [], | |
"compiler": { | |
"tsconfigFilePath": "<projectFolder>/tsconfig.json", | |
"overrideTsconfig": { | |
"compilerOptions": { | |
"outDir": "build" | |
} | |
} | |
}, | |
"dtsRollup": { | |
"enabled": true, | |
"untrimmedFilePath": "<projectFolder>/dist/index.d.ts" | |
}, | |
"apiReport": { | |
"enabled": false | |
}, | |
"docModel": { | |
"enabled": false | |
}, | |
"tsdocMetadata": { | |
"enabled": false | |
}, | |
"messages": { | |
"compilerMessageReporting": { | |
"default": { | |
"logLevel": "none" | |
} | |
}, | |
"extractorMessageReporting": { | |
"default": { | |
"logLevel": "none" | |
} | |
}, | |
"tsdocMessageReporting": { | |
"default": { | |
"logLevel": "none" | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "my-lib", | |
"version": "1.0.0", | |
"description": "Really awesome thing this does", | |
"author": "Me <[email protected]> (https://www.website.com)", | |
"homepage": "https://github.com/<username>/my-lib", | |
"keywords": [ | |
"something", | |
"awesome" | |
], | |
"main": "dist/my-lib.cjs.js", | |
"module": "dist/my-lib.esm.js", | |
"browser": "dist/my-lib.umd.js", | |
"files": [ | |
"dist" | |
], | |
"scripts": { | |
"dev": "rollup -c -w", | |
"build": "rollup -c", | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"dependencies": { | |
"@rollup/plugin-commonjs": "^19.0.0", | |
"@rollup/plugin-node-resolve": "^13.0.0", | |
"@rollup/plugin-typescript": "^8.2.1", | |
"eslint": "^7.26.0", | |
"rollup": "^2.47.0", | |
"ts-node": "^9.1.1", | |
"tslib": "^2.2.0", | |
"typescript": "^4.2.4" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import resolve from "@rollup/plugin-node-resolve"; | |
import commonjs from "@rollup/plugin-commonjs"; | |
import typescript from "@rollup/plugin-typescript"; | |
import pkg from "./package.json"; | |
export default [ | |
// browser-friendly UMD build | |
{ | |
input: "src/index.ts", | |
output: { | |
name: "myLib", | |
file: pkg.browser, | |
format: "umd", | |
}, | |
plugins: [ | |
resolve(), | |
commonjs(), | |
typescript({ tsconfig: "./tsconfig.json" }), | |
], | |
}, | |
// CommonJS (for Node) and ES module (for bundlers) build. | |
// (We could have three entries in the configuration array | |
// instead of two, but it's quicker to generate multiple | |
// builds from a single configuration where possible, using | |
// an array for the `output` option, where we can specify | |
// `file` and `format` for each target) | |
{ | |
input: "src/index.ts", | |
output: [ | |
{ file: pkg.main, format: "cjs" }, | |
{ file: pkg.module, format: "es" }, | |
], | |
plugins: [typescript({ tsconfig: "./tsconfig.json" })], | |
}, | |
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"compilerOptions": { | |
"target": "es6", | |
"module": "esnext", | |
"moduleResolution": "node", | |
"strict": true, | |
"esModuleInterop": true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment