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

@moped/rule-ts

v0.0.10

Published

This module provides a sensible rule for handling typescript in webpack applications. It is part of the moped suite of utilities for creating composable configs for building node.js and react apps.

Downloads

21

Readme

rule-ts

This module provides a sensible rule for handling typescript in webpack applications. It is part of the moped suite of utilities for creating composable configs for building node.js and react apps.

In development, the result of transforming typescript files are cached in .cache/typescript and the transformation is parallelised across multiple threads. This also means that it does not type check in development. In production, it takes the slower approach of compiling every file individually. This is necessary to alow const enums to be stripped from the output.

Installation

yarn add --dev @moped/rule-ts

Usage

const createTsRule = require('@moped/rule-ts');

module.exports = {
  entry: __dirname + '/src/index.ts',
  output: {
    path: __dirname + '/build',
    filename: 'static/js/[name].[chunkhash:8].js',
    publicPath: '/',
  },
  resolve: {
    extensions: ['.ts', '.tsx', '.js', '.json'],
  },
  module: {
    rules: [createTsRule()],
  },
};

Usage with rule-file and rule-css

To use with other loaders, you have two options. You can use require instead of ES imports, this will effectively just give you an any. Alternatively, you can add a declaration for the type of module you want to import. e.g.

declare module '*.png' {
  export= string;
}

The wildcard allows this to match all .png files.

Type checking in development

To maximise reload times, this module does not actually do any type checking in development. You can use ForkTsCheckerWebpackPlugin in development to add type checking, without compromising build time.

Options

Options.environment

This can be 'development', 'production' or 'test'. If you don't provide it, it will default to the value of NODE_ENV. If neither are specified, an exception will be thrown. It will also throw an exception if any value other than 'development', 'production' and 'test' is used.

Options.srcDirectory

This is the directory that your source code lives in, it should not include your node_modules folder. It will default to src. Files outside of this folder are not transformed.

Options.babelPresets

An array of file names for babel presets. If you add this option, babel will be used to transform the code after it has been transformed by typescript. If you do not add this option, the code is only transformed by typescript. The babel transform will never use babelrc files.

Options.tsConfigFileName

The filename for your tsconfig file.

Options.tsCompilerOptions

Overrides for the compilerOptions section of your tsconfig. @moped/rule-ts automatically enables preserveConstEnums in development.

Options.disableSourceMaps

If you are building a very large application, generating source maps may become too slow, and might not be worth it. You can use this option to disable source maps. You can alternatively set the GENERATE_SOURCEMAP environment variable to false (this option is for compatibility with create-react-app).

Options.workers

If you have a very large number of modules, and a computer with many cores, you can pass a number of workers to make typescript compilation multi-threaded. This is not enabled by default, because it has a very big overhead. When I've experimented with this, it's usually been faster to leave it turned off.

N.B. If you enable workers, it is still only used in development. Also, workers prevent this module from reporting syntax errors, so you will need to use new ForkTsCheckerWebpackPlugin({ checkSyntacticErrors: true }) instead of new ForkTsCheckerWebpackPlugin() if using ForkTsCheckerWebpackPlugin.

Licence

MIT