1.0.1 • Published 6 years ago

stackoverflow-47210046 v1.0.1

Weekly downloads
4
License
Apache 2.0
Repository
github
Last release
6 years ago

stackoverflow-47210046

This is just another boilerplate example on publishing a package written in TypeScript. The corresponding stackoverflow.com question can be found here.

Quick start

git clone https://github.com/kittaakos/stackoverflow-47210046.git \
&& cd stackoverflow-47210046 \
&& npm i \
&& npm run build \
&& npm run test

Build

npm run build

Test

npm run test

Some remarks

  • Make sure you have added "dom" to the libraries in the tsconfig.json to include them during the compilation.
  • Add "main": "lib/index" to the package.json. You can see, it points to the compiled output and has no file extension.
  • Adde "typings": "lib/index" to the package.json.
  • Although the lib output folder is not added to version control, that will be available on npmjs.org.
  • The tests will be executed with ts-node so the tsc compilation can be omitted.
  • If you want to run your test in watch mode, execute npm run test -- -w.
  • If you want to run your tsc compiler in watch mode, execute npm run build -- -w.

Use the published npm package

mkdir tmp-client \
&& cd tmp-client \
&& npm init -y \
&& npm i -D typescript ts-node \
&& npm i -S stackoverflow-47210046 \
&& echo "const MyAwesomeComponent = require('stackoverflow-47210046').MyAwesomeComponent; console.log(new MyAwesomeComponent().render());" > main_js.js \
&& node main_js \
&& echo "import { MyAwesomeComponent } from 'stackoverflow-47210046'; console.log(new MyAwesomeComponent().render());" > main_ts.ts \
&& ./node_modules/.bin/ts-node main_ts.ts