- compliant: Uses rollup.js to build your NPM module in multiple formats (ESM and CJS) to support all major use cases for NPM.
- testable: built for TDD with hot-reloading, code coverage, snapshots, and more with Jest.
- isomorphic: supports testing in both node and browsers with jsdom for DOM emulation in tests
- compatible: write cutting-edge Typescript and it will compile it to a version that older browsers support. Supports loading of
.svgfiles as React components using rollup. - consistent: uses eslint to automatically enforce code standards via git hooks using husky and lint-staged, and commitzen to enforce
git commitstandards - continuous: uses Travis CI and Coveralls to create an CI pipeline that builds your code on merges to master, runs tests, and reports on code coverage.
-
npm testornpm test -- --watchornpm test -- --watchAll- Runs jest tests in the terminal
- Optional
watchflag only reruns tests that are affected by file changes - Optional
watchAllflag will rerun all tests when something changes
-
npm run build- Builds your module for publishing via npm
- Creates two variants:
- ESM (
index.es.js) - Set as the value formodulein thepackage.jsonfile. Allows bundlers that support ES modules (like webpack and rollup) to use this module and get benefits like tree shaking. - CommonJS (
index.js) - Set as the value formainin thepackage.jsonfile. This is the standard format for NPM modules.
- ESM (
- Creates an
index.cssthat can be imported by adopters using an import likeimport 'your-npm-module/dist/index.css'; - Updates a
demo.jsbundle in/docsso that you can see a demo of your NPM package served atdocs/index.html
-
npm start- Uses the
src/demo.tsxfile to build a "demo" implementation of your module. You can customizesrc/demo.tsxas needed. - Serves your demo app at http://localhost:10001/
- Runs rollup in watch mode, so any changes to your source code will trigger a rebuild of your bundle
- Note: Bundle changes still require a reload of the browser page
- Uses the
-
npm run cm- Uses commitizen to prompt for required commit fields to ensure a standardized commit message
-
npm run lint- Lints your entire project using eslint and reports any errors
-
Clone the repository into your "new-project" directory
git clone https://github.com/ctaylo21/TypescriptReactBoilerplate.git new-project && cd new-project
-
Remove the git repository, and then initialize a new one
rm -rf .git && git init -
Remove README and replace with your own
rm README.md && touch README.md -
Update
package.jsonand install dependenciesnpm init && npm installDon't forget to update the description and any URL's in the
package.jsonfile. -
Start coding!
Once you have created and pushed your new repo to GitHub:
-
Sign in to (or create) your Travis CI account and follow the instructions to enable Travis CI on your repo. This repo already includes a
.travis.yml, so you only need to active your repo.- (Optional): Add your Travis-CI badge to the README
-
Add your repo to your coveralls account. Then, grab the token from coveralls and put it in a new file called
.coveralls.ymlfile at the project root. It should contain:repo_token: <your_repo_token>- (Optional): Add your Coveralls badge to the README
-
By running
npm run build, a demo of your app will be created in the/docsfolder based upon thesrc/demo.tsxfile. Then, you can go to your GitHub repo > settings > GitHub Pages and update theSourceto point tomaster branch / docs folder. Then, you have a functioning demo of your page athttps://<your-github>.github.io/<your-repo-name>/ -
(Optional): Add a badge that shows the status of your NPM dev dependencies from david-dm.org.
If you find any problems or bugs, please open a new issue.