1. Or create a folder with the name of the package you want to use
mkdir <package-name>
2. Generate a package.json file (answering the questions on de cli)
npm init -y
3. Install the latest typescript version globally
npm i -g typescript@latest
3. Install typescript as development dependency (saving to package.json)
npm install typescript --save-dev
4. Generate a .tsconfig file
.\node_modules\.bin\tsc --init or ./node_modules/.bin/tsc --init or tsc --init
5. in .tsconfig set:
"declaration": true, /* Generates corresponding '.d.ts' file. */ "sourceMap": true, /* Generates corresponding '.map' file. */
6. In package.json set:
{ "bin" : { "my-executable" : "./dist/index.js" } }, /* when exporting an executable*/ "main": "dist/index.js", /* when exporting a library */ "types": "dist/index.d.ts", /* typescript type definition file */ "scripts": { "build": "tsc --listEmittedFiles", "install": "tsc --listEmittedFiles", /* optional: when installing build project */ "test": "jasmine --config=jasmine.json", } }
7. Install dependencies for unit-tests
npm install --save-dev jasmine ./node_modules/.bin/jasmine init
Add a .gitignore file
# compiled output
/dist
/tmp
/out-tsc
# dependencies
/node_modules
.project
*.launch
.settings/
.vscode/
# misc
npm-debug.log
/typings
# e2e
/e2e/*.js
/e2e/*.map
# compiled output
/dist
/tmp
/out-tsc
# dependencies
/node_modules
.project
*.launch
.settings/
.vscode/
# misc
npm-debug.log
/typings
# e2e
/e2e/*.js
/e2e/*.map
# compiled output /dist /tmp /out-tsc # dependencies /node_modules .project *.launch .settings/ .vscode/ # misc npm-debug.log /typings # e2e /e2e/*.js /e2e/*.map
Add an .npmignore file
src/
src/
src/
# Maak een nieuwe map voor het projectmkdir MyProjectcd MyProject# Maak een nieuw TypeScript-projectnpm init -ynpm install typescript --save-devnpx tsc --init# Maak .gitignore en .npmignore bestandenNew-Item -ItemType File -Path .\.gitignore -Value "node_modules/"New-Item -ItemType File -Path .\.npmignore -Value "node_modules/"# Add jasminenpm install --save-dev jasminenpx jasmine init
101500cookie-checkStarter: Create new (typescript enabled) NPM package from scratch