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

typewiz-webpack

v1.2.4

Published

A Webpack plugin that automatically adds types to TypeScript code using [typewiz-core](https://www.npmjs.com/package/typewiz-core)

Downloads

41

Readme

typewiz-webpack

A Webpack plugin that automatically adds types to TypeScript code using typewiz-core

Build Status Coverage Status

Prerequisites

Make sure you are using a recent version of webpack-dev-server. Version 2.9.0 or newer is required.

Installation

First, install the plugin:

yarn add typewiz-webpack

or

npm install --save typewiz-webpack

Then, add typewiz-webpack to your list of loaders, just after your usual TypeScript loader. e.g.:

  module: {
    rules: [
      {
        test: /\.tsx?$/,
        loaders: ['awesome-typescript-loader', 'typewiz-webpack']
      }
    ]
  },

Optionally you can also specify the path to your typewiz.json file:

  module: {
    rules: [
      {
        test: /\.tsx?$/,
        loaders:[
          'awesome-typescript-loader',
          {
            loader:'typewiz-webpack',
            options:{
              typewizConfig: path.resolve(__dirname, "../typewiz.json")
            }
          }
        ]
      }
    ]
  },

Next, add TypewizPlugin to your list of plugins, and configure your webpack-dev-server to save the collected type info to disk using the provided typewizCollectorMiddleware middleware. Here is an example of what your final config file may look like:

const { CheckerPlugin } = require('awesome-typescript-loader');
const { TypewizPlugin, typewizCollectorMiddleware } = require('typewiz-webpack');

module.exports = {
  resolve: {
    extensions: ['.ts', '.tsx', '.js', '.jsx']
  },

  devtool: 'source-map',

  module: {
    rules: [
      {
        test: /\.tsx?$/,
        loaders: ['awesome-typescript-loader', 'typewiz-webpack']
      }
    ]
  },

  plugins: [
    new CheckerPlugin(),
    new TypewizPlugin()
  ],

  devServer: {
    before: function(app) {
      typewizCollectorMiddleware(app, 'collected-types.json');
    }
  }
};

Finally, run your app with webpack. The collected type information will be saved to disk inside collected-types.json. To apply the types to your source code install the typewiz cli and run the apply command:

typewiz applyTypes collected-types.json

Check out typewiz-webpack-demo for a complete example of WebPack + TypeWiz setup.

Example

Given the following input file:

function greet(who) {
    return `Hello, ${who}`;
}

console.log(greet('Uri'));

After instrumenting the code with the plugin, collecting the types and applying them, you will get the following result:

function greet(who: string) {
    return `Hello, ${who}`;
}

console.log(greet('Uri'));

Note the addition of the : string type for the who parameter in the first line.

License

MIT