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

rollup-plugin-ts-compiler

v1.0.18

Published

Fast and efficient Typescript compiler plugin for Rollup

Downloads

571

Readme

rollup-plugin-ts-compiler

Fast and efficient Typescript compiler plugin for Rollup. All included: compiler errors, incremental build, declarations, source maps, monorepo support and more.

Installation

npm install rollup-plugin-ts-compiler

Usage

import typescript from 'rollup-plugin-ts-compiler';

export default {
    input: './main.ts',
    plugins: [
        typescript(/*{ plugin options }*/)
    ]
}

The plugin inherits all compiler options and file lists from your tsconfig.json file.

Options

  • compilerOptions: {}
    Overrides compilerOptions values from tsconfig.json.
 typescript({
     compilerOptions: {
        "module": "commonjs",
        "target": "es5",
     }
 })
  • monorepo: boolean
    Set to true if you are working in monorepo. By default in watch mode plugin caches and never recompiles node_modules and all files outside of your project root. But in monorepo we want to check and recompile files outside since they can be other local packages.

  • sharedState: {}
    See below.

Further optimization

Plugin allows you to reuse compile results with many Rollup inputs/outputs if you have same compilerOptions for all of them. Just pass an object to plugin instances as "sharedState" option.

For example build with multiple formats:

import typescript from 'rollup-plugin-ts-compiler';
import pkg from './package.json';

const sharedState = {};

export default [
    {
        input: './main.ts',
        output: { 
            file: resolve(__dirname, pkg.main), 
            format: 'cjs'
        },
        plugins: [
             typescript({
                sharedState
            })
        ],
    },
    {
        input: './main.ts',
        output: { 
            file: resolve(__dirname, pkg.module), 
            format: 'esm'
        },
        plugins: [
             typescript({
                sharedState
            })
        ],
    },
];

Plugin will compile files only for the first input, second one will be emitted almost instantly. You can use shared state even for different inputs since when Typescript Compiler starts, it compiles all files it can find by "include" and "exclude" of your tsconfig (default TSC behavior)

One caveat

Plugin uses modern Typescript Compiler API with incremental program by default which makes it way much faster than rollup-plugin-typescript2 or @rollup/plugin-typescript.
It was implemented via fully delegating compiling to Typescript Compiler which reads files directly from file system and then gives output to Rollup. Therefore Rollup's preceding pipeline is ignored.

That is usually acceptable since you need only one plugin to compile .ts files and you can't have other plugins working with typescript code. Just make sure that in your plugin array inside Rollup options this plugin placed before babel or similar.