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

@shopify/loom-plugin-rollup

v1.0.2

Published

A loom plugin that runs rollup as a build step

Downloads

9,201

Readme

@shopify/loom-plugin-rollup

Exposes hooks and build step to run rollup.

Installation

$ yarn add @shopify/loom-plugin-rollup --dev

Usage

The low-level functionality of this package is split into two parts.

  • rollupHooks is a plugin that exposes hooks to configure rollup.
  • rollupBuild is a plugin that registers a build step that runs rollup with the configuration gathered by the hooks defined in rollupHooks.

Add both plugins to your project, along with configuration of the hooks. This example configures the rollupInputOptions and rollupOutputs hooks.

import {createPackage, Runtime, createProjectBuildPlugin} from '@shopify/loom';
import {rollupHooks, rollupBuild} from '@shopify/loom-plugin-rollup';

export default createPackage((pkg) => {
  pkg.use(rollupHooks(), rollupBuild(), rollupConfig());
});

function rollupConfig() {
  return createProjectBuildPlugin('Test', ({hooks, project}) => {
    hooks.target.hook(({hooks}) => {
      hooks.configure.hook((configuration) => {
        configuration.rollupInputOptions?.hook(() => {
          return {input: project.fs.resolvePath('./src/index.js')};
        });
        configuration.rollupOutputs?.hook(() => {
          return [{format: 'esm', dir: project.fs.buildPath('esm')}];
        });
      });
    });
  });
}

Hooks

The rollupInput, rollupPlugins and rollupExternal hooks map to input, plugins and externals keys of Rollup's InputOptions object as documented at https://rollupjs.org/guide/en/#inputoptions-object.

The rollupInputOptions hook defines a whole InputOptions object, it includes any values set in rollupInput, rollupPlugins and rollupExternal, this can be used if you need to control any advanced input configuration options.

The rollupOutputs hook is an array of Rollup's OutputOptions objects as documented at https://rollupjs.org/guide/en/#outputoptions-object.

rollupPlugins Helper

This package exports a rollupPlugins loom plugin that provides a shorthand to add items to the rollupPlugins hook. Give this plugin either an array of rollup plugins, or a function that takes a loom Target and returns an array of rollup plugins. This allows you to control what plugins are added based upon the Target.

import {createPackage, Runtime, createProjectBuildPlugin} from '@shopify/loom';
import {
  rollupHooks,
  rollupBuild,
  rollupPlugins,
} from '@shopify/loom-plugin-rollup';

export default createPackage((pkg) => {
  pkg.use(
    rollupHooks(),
    rollupBuild(),
    rollupConfig(),
    // Adds the injecterPlugin to all targets with the same config
    rollupPlugins([injecterPlugin('all')]),
    // Only adds the injecterPlugin when compiling the target with the specialBuild option set
    rollupPlugins((target) => {
      return target.options.specialBuild
        ? [injecterPlugin('only specialBuild')]
        : [];
    }),
  );

  // A sample Rollup plugin that shall append some content to each file
  function injecterPlugin(string) {
    return {
      name: `test-injecter`,
      transform(code) {
        return code + '/*Injected content ~' + string + '~ */';
      },
    };
  }
});

function rollupConfig() {
  return createProjectBuildPlugin('Test', ({hooks, project}) => {
    hooks.target.hook(({hooks}) => {
      hooks.configure.hook((configuration) => {
        configuration.rollupInputOptions?.hook(() => {
          return {input: project.fs.resolvePath('./src/index.js')};
        });
        configuration.rollupOutputs?.hook(() => {
          return [{format: 'esm', dir: project.fs.buildPath('esm')}];
        });
      });
    });
  });
}