0.4.4 • Published 3 years ago

@fangdh/typescript-esbuild-2021 v0.4.4

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

TypeScript Boilerplate for 2021

Build and test status

TypeScript project boilerplate with modern tooling, for Node.js programs, libraries and browser modules. Get started quickly and right-footed 🚀

See also the introduction blog post: Starting a TypeScript Project in 2021.

Getting Started

# Clone the repository (you can also click "Use this template")
git clone https://github.com/metachris/typescript-boilerplate.git your_project_name
cd your_project_name

# Edit `package.json` and `tsconfig.json` to your liking
...

# Install dependencies
yarn install

# Now you can run various yarn commands:
yarn cli
yarn lint
yarn test
yarn build-all
yarn ts-node <filename>
yarn esbuild-browser
...
  • Take a look at all the scripts in package.json
  • For publishing to npm, use yarn publish (or npm publish)

esbuild

esbuild is an extremely fast bundler that supports a large part of the TypeScript syntax. This project uses it to bundle for browsers (and Node.js if you want).

# Build for browsers
yarn esbuild-browser:dev
yarn esbuild-browser:watch

# Build the cli for node
yarn esbuild-node:dev
yarn esbuild-node:watch

You can generate a full clean build with yarn build-all (which uses both tsc and esbuild).

  • package.json includes scripts for various esbuild commands: see here
  • esbuild has a --global-name=xyz flag, to store the exports from the entry point in a global variable. See also the esbuild "Global name" docs.
  • Read more about the esbuild setup here.
  • esbuild for the browser uses the IIFE (immediately-invoked function expression) format, which executes the bundled code on load (see also https://github.com/evanw/esbuild/issues/29)

Tests with Jest

You can write Jest tests like this:

import { greet } from './main'

test('the data is peanut butter', () => {
  expect(1).toBe(1)
});

test('greeting', () => {
  expect(greet('Foo')).toBe('Hello Foo')
});

Run the tests with yarn test, no separate compile step is necessary.

Documentation, published with CI

You can auto-generate API documentation from the TyoeScript source files using TypeDoc. The generated documentation can be published to GitHub / GitLab pages through the CI.

Generate the documentation, using src/main.ts as entrypoint (configured in package.json):

yarn docs

The resulting HTML is saved in docs/.

You can publish the documentation through CI:

This is the documentation for this boilerplate project: https://metachris.github.io/typescript-boilerplate/

References

Feedback

Reach out with feedback and ideas:

acorn-jsxacorn-globalsacornajvababansi-regexansi-colorsansi-escapesansi-stylesacorn-walkanymatchargargparsearr-flattenarr-unionarr-diffarray-unionarray-uniqueasn1assign-symbolsassert-plusastral-regexasynckitat-least-nodeatobaws-sign2babel-jestaws4babel-plugin-istanbulbabel-plugin-jest-hoistbabel-preset-jestbasebcrypt-pbkdfbabel-preset-current-node-syntaxbrace-expansionbracesbrowserslistbrowser-process-hrtimebserbs-loggerbalanced-matchbuffer-fromcallsitescache-basecaniuse-litecapture-exitcamelcasechalkcaselesschar-regexcjs-module-lexerci-infococlass-utilscliuicolor-namecollection-visitcollect-v8-coveragecolor-convertcombined-streamcolorscomponent-emittercoloretteconvert-source-mapcopy-descriptorcore-util-isconcat-mapcross-spawncssomcreate-requirecssstyledata-urlsdashdashdecamelizedecode-uri-componentdeep-isdebugdecimal.jsdefine-propertydetect-newlinedeepmergedelayed-streamdiffdiff-sequencesdir-globdoctrinedomexceptionelectron-to-chromiumemitteryecc-jsbnemoji-regexend-of-streamescaladeenquirererror-exescape-string-regexpeslint-scopeescodegeneslint-utilseslint-visitor-keysespreeesprimaestraverseesrecurseesqueryesutilsexec-shexecaexitexpectextend-shallowexpand-bracketsextendextglobextsprintffast-globfast-deep-equalfastqfast-json-stable-stringifyfast-levenshteinfb-watchmanfind-upfile-entry-cachefor-infill-rangeflat-cacheflattedform-dataforever-agentfs-extrafragment-cachefs.realpathfseventsfunctional-red-black-treefunction-bindget-caller-filegensyncget-package-typeglobget-streamgetpassget-valueglob-parentglobalsglobbygrowlygraceful-fshandlebarshar-schemahar-validatorhashas-valuehas-flaghas-valueshosted-git-infohttp-signaturehtml-escaperhtml-encoding-sniffericonv-litehuman-signalsimport-freshignoreinflightimport-localimurmurhashinheritsis-accessor-descriptorinterpretis-arrayishis-bufferis-ciis-descriptoris-data-descriptoris-dockeris-core-moduleis-generator-fnis-fullwidth-code-pointis-extendableis-numberis-plain-objectis-extglobis-potential-custom-element-nameis-streamis-globisarrayis-typedarrayis-wslis-windowsisstreamistanbul-lib-coverageisexeisobjectistanbul-lib-instrumentistanbul-lib-reportistanbul-lib-source-mapsistanbul-reportsjest-configjest-clijest-changed-filesjest-docblockjest-diffjest-eachjest-environment-jsdomjest-get-typejest-haste-mapjest-environment-nodejest-message-utiljest-leak-detectorjest-matcher-utilsjest-jasmine2jest-mockjest-resolvejest-pnp-resolverjest-regex-utiljest-resolve-dependenciesjest-runnerjest-snapshotjest-runtimejest-watcherjest-serializerjest-utiljest-workerjs-yamljest-validatejsdomjsbnjs-tokensjson-parse-even-better-errorsjsescjson-schemajson-schema-traversejson-stable-stringify-without-jsonifyjson-stringify-safejson5jsonfilejsprimkleurkind-oflevenlevnlines-and-columnslocate-pathlodashlodash.clonedeeplodash.truncatelru-cachelunrmake-dirmake-errormakeerrormap-visitmap-cachemarkedmerge-streammime-dbmerge2micromatchmime-typesmimic-fnminimatchminimistmixin-deepmkdirpnatural-comparemsnanomatchnode-modules-regexpnice-tryneo-asyncnode-int64node-notifiernormalize-package-datanode-releasesnormalize-pathnpm-run-pathnwsapiobject-copyoauth-signonceobject-visitobject.pickonetimeoptionatoronigasmp-finallyp-each-seriesp-locatep-limitp-tryparent-moduleparse-jsonpascalcaseparse5path-existspath-is-absolutepath-keypath-typepath-parseperformance-nowpiratespkg-dirposix-character-classespretty-formatprelude-lsprogresspslpumppromptspunycodeqsqueue-microtaskread-pkgread-pkg-uprechoirreact-isregex-notregexppremove-trailing-separatorrepeat-elementrepeat-stringrequestrequest-promise-nativerequest-promise-corerequire-directoryrequire-from-stringrequire-main-filenameresolve-cwdresolve-fromresolve-urlretreusifyresolverimrafrsvprun-parallelsafe-regexsafe-buffersafer-buffersanesaxessemverset-valueset-blockingshebang-regexshelljsshebang-commandshellwordsshikisisteransisignal-exitslashslice-ansisnapdragonsnapdragon-nodesource-map-resolvesnapdragon-utilsource-map-supportsource-mapsource-map-urlspdx-exceptionsspdx-correctspdx-license-idssplit-stringspdx-expression-parsesshpkstack-utilsstatic-extendsprintf-jsstealthy-requirestring-widthstring-lengthstrip-ansistrip-bomsupports-colorstrip-eofstrip-json-commentssupports-hyperlinksstrip-final-newlinetableterminal-linksymbol-treetest-excludetext-tablethroatto-object-pathto-fast-propertiesto-regextmpltslibto-regex-rangetr46tough-cookietunnel-agenttsutilstweetnacltype-checktype-detecttypedarray-to-buffertype-festuniversalifyunion-valueuglify-jsunset-valuetypedoc-default-themesurixuri-jsuseuuidv8-compile-cachevalidate-npm-package-licensev8-to-istanbulvscode-textmateverrorw3c-hr-timew3c-xmlserializerwalkerwebidl-conversionswhatwg-mimetypewhatwg-encodingpicomatchwhatwg-urlwhich-moduleword-wrapwrappywordwrapwhichwrap-ansiwrite-file-atomicxmlcharsxml-name-validatorwsyargsy18nynyargs-parseryallist
0.4.4

3 years ago

0.4.3

3 years ago