GithubHelp home page GithubHelp logo

wjentner / typescript-lib-starter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hotell/typescript-lib-starter

0.0 1.0 0.0 335 KB

Typescript library starter

TypeScript 14.65% JavaScript 85.35%

typescript-lib-starter's Introduction

Typescript lib starter

Greenkeeper badge

Build Status NPM version Standard Version styled with prettier Conventional Commits

This npm library starter:

  • creates package for both Node and Browser
  • build creates 3 standard "bundle" formats:
    • main -> UMD bundle for Node and Browser
    • module -> transpiled files to ES5 + es2015 modules for tree shaking
    • es2015 -> raw files transpiled to latest ES standard ( es2017 ) ( this is useful if you wann transpile everthing or just wann ship untranspiled esNext code for evergreen browsers)
  • also we provide experimantal FESM bundle thanks to Webpack 3 and scope hoisting -> you can find it in lib-fesm folder ( scope hoisting is now enabled also within UMD == smaller payload size )
  • type definitions are automatically generated and shipped with your package

Start coding jedi!

git clone https://github.com/Hotell/typescript-lib-starter <your-libary-folder-name>

cd <your-libary-folder-name>

rm -rf .git && git init

Open package.json and reset following fields:

  • name
  • version ( It is recommended to start from 1.0.0 )
  • description
  • main ( "umd/typescript-lib-starter.js" => "umd/{name}.js" )
  • repository.url
  • author
  • license ( use whatever you want )

Now install all dependencies

yarn install

Happy coding !

Consumption of published library:

yarn add my-new-library or npm install my-new-library

Webpack

// main.ts
import { Greeter } from 'my-new-library';

const mountPoint = document.getElementById('app');
const App = () => {
  const greeter = new Greeter('Stranger');
  return `<h1>${greeter.greet()}</h1>`
}
const render = (Root: Function, where: HTMLElement) => {
  where.innerHTML = Root();
}

render(App, mountPoint);
<html>
  <head>
    <script src="bundle.js" async></script>
  </head>
  <body>
    <div id="app"></div>
  </body>
</html>

UMD ( no bundler )

<html>
  <head>
    <script src="node_modules/my-lib/umd/my-new-library.min.js"></script>
    <script async>
        var Greeter = MyLib.Greeter;

        var App = function() {
          var greeter = new Greeter('Stranger');
          return '<h1>'+greeter.greet()+'</h1>'
        }
        var render = function(Root, where) {
          where.innerHTML = Root();
        }

        render(App, mountPoint);
    </script>
  </head>
  <body>
    <div id="app"></div>
  </body>
</html>

Publishing/Release

NOTE: you have to create npm account and register token on your machine -> npm adduser

If you are using scope don't forget to --scope

yarn release

which will do following:

  • bump version and tag
  • updates/creates CHANGELOG.md
  • pushes to github master branch
  • publishes build package to npm

releases are handled by awesome standard-version

Initial Release (without bumping package.json version):

yarn release -- --first-release

Pre-release

  • To get from 1.1.2 to 1.1.2-0:

yarn release -- --prerelease

  • Alpha: To get from 1.1.2 to 1.1.2-alpha.0:

yarn release -- --prerelease alpha

  • Beta: To get from 1.1.2 to 1.1.2-beta.0:

yarn release -- --prerelease beta

Dry run mode

See what commands would be run, without committing to git or updating files

yarn release -- --dry-run

Check what files gonna be published to npm

  • CLI output via yarn release:preflight
  • or yarn release:preflight:package will create tarball which you can check

Check size of your published NPM bundle

run yarn build then npm run size

Format and fix lint errors

yarn ts:style:fix

Generate documentation

yarn docs

Commit ( via commitizen )

  • this is preffered way how to create convetional-changelog valid commits
  • if you preffer your custom tool we provide a commit hook linter which will error out, it you provide invalid commit message
  • if you are in rush and just wanna skip commit message valiation just prefix your message with WIP: something done ( if you do this please squash your work when you're done with proper commit message so standard-version can create Changelog and bump version of your library appropriately )

yarn cz - will invoke commitizen CLI

Note

import()

This starter uses latest typescript >=2.4 which adds supprot for lazy loading chunks/modules via import().

Please note that if you wanna use that feature, compiler will complain because declaration generation is turned on, and currently TS can't handle type generation with types that will be loaded in the future ( lazily )

How to solve this:

  • turn of type checking and don't generate types for that lazy import: import('./components/button') as any
  • or you can use this temporary workaround

typescript-lib-starter's People

Contributors

hotell avatar wjentner avatar greenkeeper[bot] avatar elboman avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.