# @shopify/loom-plugin-rollup

> A loom plugin that runs rollup as a build step

Latest version **1.0.2** (published 2022-08-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install @shopify/loom-plugin-rollup
pnpm add @shopify/loom-plugin-rollup
yarn add @shopify/loom-plugin-rollup
bun add @shopify/loom-plugin-rollup
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2022-08-23 |
| First published | 2021-09-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | ^12.22.0 \|\| ^14.17.0 \|\| >=16.0.0 |
| Dependencies | 2 |
| Unpacked size | 13.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Shopify Inc. |
| Maintainers | wcandillon, jplhomer, marytal, themallen, nathanpjf, shopify-dep, goodforonefare, lemonmade, vsumner, wizardlyhel, antoine.grant, tsov, andyw8-shopify, henrytao, hannachen, andrewapperley, iainmcampbell, vividviolet, bpscott |

## Links

- npm: https://www.npmjs.com/package/@shopify/loom-plugin-rollup
- Repository: https://github.com/Shopify/loom
- Homepage: https://github.com/Shopify/loom/blob/main/packages/loom-plugin-rollup/README.md
- Issues: https://github.com/Shopify/loom/issues
- npm.io page: https://npm.io/package/@shopify/loom-plugin-rollup

## Dependencies (2)

- [rollup](https://npm.io/package/rollup.md) ^2.60.1
- [@shopify/loom](https://npm.io/package/@shopify/loom.md) ^1.0.2

## Recent versions

- 1.0.2 (latest) — 2022-08-23
- 0.5.0-alpha.0 (beta) — 2021-10-12
- 1.0.1 — 2021-11-23
- 1.0.0 — 2021-10-22
- 0.5.0-alpha.4 — 2021-10-15
- 0.5.0-alpha.3 — 2021-10-15
- 0.5.0-alpha.2 — 2021-10-15
- 0.5.0-alpha.1 — 2021-10-13
- 0.4.0 — 2021-09-13

## README

# `@shopify/loom-plugin-rollup`

Exposes hooks and build step to run [`rollup`](https://rollupjs.org/guide/en/).

## Installation

```sh
$ 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.

```js
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`.

```js
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')}];
        });
      });
    });
  });
}
```

---
_Source: https://npm.io/package/@shopify/loom-plugin-rollup · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
