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-typescript-plugin-projects

v0.5.10

Published

<p> <a href="https://www.npmjs.com/package/rollup-typescript-plugin-projects"><img src="https://img.shields.io/npm/v/rollup-typescript-plugin-projects" alt="npm package"></a> </p> Early prototype plugin Typescript References for Rollup.

Downloads

4

Readme

rollup-typescript-plugin-projects

Current Outstanding Issues:

  • Errors are not captured gracefully.
  • Compiling Times are quite slow.
  • I am suspecting watches are causing colliding multiple compilations.
  • CWD is fixed to the folder rollup is run on.
  • includeUnusedFiles could be done per project, as of right now it's a global toggle.
    • It does not currently support a single file output. This is due to how rollup handles isolated chunks. Will need to look into this more.

Install

Using npm:

npm install rollup-typescript-plugin-projects --save-dev

Using yarn:

yarn add rollup-typescript-plugin-projects --dev

Basic Usage

Create a rollup.config.js configuration file and import the plugin

import typescript from "rollup-typescript-plugin-projects"
import { nodeResolve } from "@rollup/plugin-node-resolve";
import nodePolyfills from 'rollup-plugin-polyfill-node';
import commonjs from '@rollup/plugin-commonjs';
import css from "rollup-plugin-import-css";
import json from '@rollup/plugin-json';

export default {
    input: './src/index.ts',
    output: {
        dir: './dist',
        format: 'esm',
        preserveModules: true,
        preserveModulesRoot: '',
        sourcemap: true,
    },
    plugins: [
        typescript({
            includeUnusedFiles: true    // Can be toggled on to aggressivly load all files in the project
        }),
        css({output: "vendor.css"}),
        json(),
        commonjs(),
        nodePolyfills(),
        nodeResolve({ preferBuiltins: false }),
    ]
}

Options

compilerOptions

Type: CompilerOptions Default: null

Provides a global override for the TypeScript CompilerOptions. The projects option will override the settings even further if specific customizations are needed for a single project.

projects

Type: [key: string]: CompilerOptions Default: null

Use the path of a TS config to modify that project's details. This can be used to greater control one specific projects configs.

Example:

"./project/tsconfig.json": {
  compilerOptions: {
    sourceMap: true,
  }
}

includeUnusedFiles

Type: boolean Default: null

Can be toggled on to force all files to be loaded into the TypescriptPlugin, even if it's not included as the src file in Rollup.

disableDeclarations

Type: boolean Default: null

Can be toggled on to force .d.ts files not be generated. This is not standard multi-project build behaviour, but is often preferred when publishing projects.

Project Setup

You will need Rollup version 1.62.1 or later for this project to fully work as intended.

The below example is a website ready configuration using ESM module loading.

import typescript from "rollup-typescript-plugin-projects"
import { nodeResolve } from "@rollup/plugin-node-resolve";
import nodePolyfills from 'rollup-plugin-polyfill-node';
import commonjs from '@rollup/plugin-commonjs';
import css from "rollup-plugin-import-css";
import json from '@rollup/plugin-json';

export default {
    input: './src/index.ts',
    output: {
        dir: './dist',
        format: 'esm',
        preserveModules: true,
        preserveModulesRoot: '',
        sourcemap: true,
    },
    plugins: [
        typescript({
            includeUnusedFiles: true    // Can be toggled on to aggressivly load all files in the project
        }),
        css({output: "vendor.css"}),
        json(),
        commonjs(),
        nodePolyfills(),
        nodeResolve({ preferBuiltins: false }),
    ]
}

If bundling is preferred, the module configuration can be turned into the following to make as a single bundled file. Please be aware that includeUnusedFiles cannot be turned on if a single output is specified.

import typescript from "rollup-typescript-plugin-projects"
import { nodeResolve } from "@rollup/plugin-node-resolve";
import nodePolyfills from 'rollup-plugin-polyfill-node';
import commonjs from '@rollup/plugin-commonjs';
import css from "rollup-plugin-import-css";
import json from '@rollup/plugin-json';

export default {
    input: './src/index.ts',
    output: {
        format: 'esm',
        sourcemap: true,
        file: 'bundle.js'
    },
    plugins: [
        typescript(),
        css({output: "vendor.css"}),
        json(),
        commonjs(),
        nodePolyfills(),
        nodeResolve({ preferBuiltins: false }),
    ]
}

Typescript config

For typescript to compile, it's important to configure the project properly, especially when loading for multiple projects.

You may choose to override configs with either a global set of compilerOptions, or you may choose to opt for a project specific config. Both configs may be used, but the project config will override any setting set on the main compilerOptions.

The projects object accepts a config path (either relative or absolute) that will then replace the existing projects settings when loaded.

export default {
    input: './src/index.ts',
    output: {
        format: 'esm',
        sourcemap: true,
        file: 'bundle.js'
    },
    plugins: [
        typescript({
          compilerOptions: {
            removeComments: true
          },
          projects: {
              "./tsconfig.json": {
                  removeComments: false
              }
          }
        }),
    ]
}

Folder Structure

A typical project folder structure might look like the following:

 - project
   - config
     - tsconfig.base.json             # Shared
   - packages
     - project1
       - IncludedFile.ts
       - tsconfig.json
   - src
     - main.ts
   - tsconfig.json

It's critical that all paths are under one single main project. You cannot have different configs with conflicting baseUrls.

Configs

You will want to create a shared config. This will be used to keep common details such as aliases. I have provided an example below for the config/typescript/tsconfig.base.json

config/typescript/tsconfig.base.json

{
  "compilerOptions": {
    "composite": true,
    "noEmit": false,
    "paths": {
      "@project1/*": ["packages/project1/*"],
      "@main/*": ["src/*"]
    }
  }
}

On the root of a project, a main tsconfig should be configured. You can modify as desired, but it's critical that a baseUrl, rootDir, and outDir are provided. This helps with the compiler. I have not tested a non outDir based project, but it should work.

project/tsconfig.base.json

{
  "extends": "./config/typescript/tsconfig.base.json",
  "include": [
    "src/*"
  ],
  "compilerOptions": {
    "module": "es2020",
    "target": "es2020",
    "strict": true,
    "baseUrl": "./",
    "rootDir": "./",
    "outDir": "./build/"
  },
  "references": [
    {
      "path": "packages/project1"
    }
  ]
}

In the package project1, create another Typescript config file to handle its own configurations. You can change project configs if necessary, but keeping them the same between projects should result in better bundles.

project/packages/project1/tsconfig.base.json

{
  "extends": "../../config/tsconfig.base.json",
  "compilerOptions": {
    "baseUrl": "../../",
    "rootDir": "../../",
    "outDir": "../../build/",
    "module": "es2020",
    "target": "es2020"
  },
  "include": ["."]
}

Reference

If you want to see what a multi-project config can look like, take a look at the test fixtures labeled mutli-project inside this repository.

How to build

To build this project you can run yarn install. You may run the following yarn commands for this project

  • yarn build Will build the project once
  • yarn watch Will build, then watch future file changes
  • yarn test Will run the jest test cases
  • yarn test-coverage Will run the jest tests and provide a coverage report in the project folder.

If you want to link this project to your existing project, you can use yarn link which will create a symlink between the two projects.

  1. Run yarn link inside the rollup-typescript-plugin-projects project. This should create a message saying the project link and how to symlink
  2. Navigate to your other project, and run yarn link rollup-typescript-plugin-projects which will link the project together.
  3. Run the steps as desired in 'How to set up a project' to get the typescript package included.