My take on a minimal template for typescript projects.
npm run dist # build & browserify (for using in vanilla js)
npm run build # build only (for developemnt)
npm run bundle # browserify only
npm init
(you will probably want to dogit init
and add.gitignore
as well)npm install --save-dev typescript browserify
./node_modules/.bin/tsc --init
- Edit the newly created
tsconfig.json
file, uncomment the"declaration"
and"outDir"
line, set"outDir"
to be"./lib"
. - Edit
package.json
to contain the following"script"
s:
"scripts": {
"dist": "npm run build && npm run bundle",
"build": "./node_modules/.bin/tsc",
"bundle": "./node_modules/.bin/browserify ./lib/index.js --s [moduleName] -o ./dist/bundle.js",
},
where [modunleName]
should be replaced with the name you want the bundled result (./dist/bundle.js
) to use when creating the module instance. Also, feel free to change the ./dist/bundle.js
part if you would like to use other file names.
- Set
"main"
inpackage.json
to be./lib/index.js
. npm run build
your package, and add the"typing"
field inpackage.json
.
Just switch out occurences of index
with [your name here]
in package.json
and it should work.