npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tsrx

v1.2.1

Published

Typescript + React

Downloads

887

Readme

TSRX

Version

TypeScript + React

This package contains the following modules:

  • Typescript > 4.3
  • React > 17
  • Jest 27 + testing-library

The builder has the following module bundlers:

  • Webpack > 5.51
  • Babel > 7.15

Install

# install tsrx
npm i -S tsrx

# install dependencies
npm i -S react react-dom typescript

# install dev dependencies
npm i -D @types/react @types/react-dom

# install test utilities
npm i -D jest @testing-library/jest-dom @testing-library/react

Setup tsconfig

Extend base tsconfig.json from TSRX folder:

{
  "extends": "tsrx/tsconfig.json",
  "compilerOptions": {}
}

Setup the script configuration

Create a js file as example below to setup the scrips command with a mininal setup:

Ex.: react.config.js

const { DefaultConfig } = require('tsrx/tools');

module.exports = DefaultConfig({
  // port to be used in development
  // will be set in webpack-dev-server
  port: 8080,
  devServer: {
    // development server
    // will open the browser
    // as soon as the project
    // was compiled
    open: true,
  },
});

Using scripts

TSRX have methods to be used in scripts of the package.json.

Is better to set unique config file for each method:

{
  "scripts": {
    "start": "tsrx start ./react.config.js",
    "build": "tsrx build ./react.config.prod.js",
    "test": "tsrx test ./react.config.test.js"
  }
}

Advanced options

Ex.: react.config.js

const { DefaultConfig } = require('tsrx/tools');

module.exports = DefaultConfig({
  /**
   * Source path of application files
   * Default = src
   */
  sourcePath: 'src',

  /**
   * Source index file of the app.
   *
   * If not provided, the index file will be search
   * on the sourcePath with these extensions => js, jsx, ts, tsx
   */
  sourceFile: 'index.ts',

  /**
   * output path for the compiled bundle.
   *
   * default = 'dist'
   */
  outputPath: 'dist',

  /**
   * port to be used in development
   * will be set in webpack-dev-server
   */
  port: 8080,

  /**
   * hostname to be used in development
   * will be set in webpack-dev-server
   *
   * default = localhost
   */
  host: 'localhost',

  /**
   * object with all enviroments to be set in
   *  - node: thru process.env
   *  - html: thru <%= htmlWebpackPlugin.options.propertyName %>
   */
  env: {
    textExample: 'Comment from Node Enviroments',
    booleanValueExample: true,
    numericValueExample: 37,
    htmlExample: 'Comment from HTML Enviroment',
  },
});

Jest customization

In case, if your tests require specific Jest configuration, include jest property in your react.config.test.js:

module.exports = DefaultConfig({
  ...
  jest: {
    coverageThreshold: {
      global: {
        branches: 50,
        functions: 50,
        lines: 50,
      },
    },
    moduleNameMapper: {
      '@components/(.*)': '<rootDir>/src/components/$1',
      '@containers/(.*)': '<rootDir>/src/containers/$1',
      '@interfaces/(.*)': '<rootDir>/src/interfaces/$1',
      '@services/(.*)': '<rootDir>/src/services/$1',
    },
    updateSnapshot: true,
  },
});

DevServer customization

In case if is necessary to customize webpack-dev-server options, just include "devServer" in your react.config.test.js:

module.exports = DefaultConfig({
  devServer: {
    open: true,
    publicPath: '/',
    contentBase: path.join(__dirname, 'dist'),
  },
  ...
});

Webpack options customization

Any properties defined in this property will override TSREX config:

module.exports = DefaultConfig({
  webpack: (config, env) => {
    // set your own webpack config
    config.output.publicPath = '/';
  },
});

Module Federation

Shared modules from webpack 5 can be configured

module.exports = DefaultConfig({
  moduleFederationOptions: {
    name: 'app-name',
    shared: ['react', 'react-dom', 'react-router-dom'],
    filename: 'remoteEntry.js',
    exposes: {
      './App': `./src/App`,
    },
  },
});

Sample Project

tsrex-sample