@lightspeed/config-typescript

2.0.3 • Public • Published

@lightspeed/config-typescript

npm version

Introduction

TypeScript configuration in a convenient package for services and libraries.

Features

// From anywhere in your app, this will resolve to `<root>/src/components/MyComponent.(js,ts,jsx,tsx)
import { MyComponent } from 'src/components/MyComponent';

Installation

First, install required dev dependencies:

yarn add -D typescript @lightspeed/config-typescript

Services

For projects that uses Babel as a transpiler and TypeScript for type-checking.

  1. Install and setup @lightspeed/babel-preset-web (or @lightspeed/babel-preset-node if in a Node.js project)

  2. Consume the TypeScript configuration by creating a tsconfig.json at the root of your project, and define baseUrl in compilerOptions for path aliasing to work:

{
  "extends": "@lightspeed/config-typescript/tsconfig.service",
  "compilerOptions": {
    "baseUrl": "."
  }
}

Note: Extending tsconfig.json from a package in node_modules requires dependency typescript@^3.2.2.

  1. Optionally, extend the configuration as you see fit (but don't forget to keep baseUrl)
{
  "extends": "@lightspeed/config-typescript/tsconfig.service",
  "compilerOptions": {
    "baseUrl": ".",
    "allowJs": true
  }
}

Nest.js

For Nest.js backend applications that use TypeScript for transpiling and type-checking. The configuration is stricter than the default generated tsconfig.json from Nest.js boilerplate applications, in particular, enabling the strict option.

  1. Consume the TypeScript configuration by creating a tsconfig.json at the root of your project, and define baseUrl in compilerOptions for path aliasing to work:
{
  "extends": "@lightspeed/config-typescript/tsconfig.nest",
  "compilerOptions": {
    "baseUrl": ".",
    "outDir": "./dist"
  }
}

Libraries

For libraries where you want to output types for external consumers, use the following configuration instead (paths may vary depending on your project structure, but those are typical ones):

{
  "extends": "@lightspeed/config-typescript/tsconfig.library",
  "compilerOptions": {
    "baseUrl": ".",
    "outDir": "dist"
  },
  "include": ["./src/**/*.ts", "./src/**/*.tsx"],
  "exclude": ["**/*.test.ts", "**/*.test.tsx"]
}

You can still extend as mentioned in the services section.

Readme

Keywords

none

Package Sidebar

Install

npm i @lightspeed/config-typescript

Weekly Downloads

686

Version

2.0.3

License

MIT

Unpacked Size

9.16 kB

Total Files

7

Last publish

Collaborators

  • kurt.bergeron
  • lightspeedhq
  • ls-guillaume-lambert
  • ls-frederic-bouchard
  • anomen