@brixtol/rollup-config

Shared Rollup configuration interface used within the Brixtol Textiles monorepo.

Usage no npm install needed!

<script type="module">
  import brixtolRollupConfig from 'https://cdn.skypack.dev/@brixtol/rollup-config';
</script>

README

@brixtol/rollup-config

Shareable rollup configuration used within the Brixtol Textiles monorepo. The module acts as an interface, it exports an instance of Rollup and several plugins that are frequently used by packages contained across the workspace. Each plugin is wrapped as a getter which help negate exposing unsed plugins on the export.

Why

We operate atop of a cloud driven serverless architecture. This module assists in the processes relating to our cloud builds, serverless apis, open/closed sourced package and applications using Lambdas or edge handlers. It provides us a single dependency import for bundling with Rollup and single source for version controlling all plugins.

Install

pnpm

pnpm add @brixtol/rollup-config -save-dev

Usage

This is an ESM module, your rollup config file must use a .mjs extension (rollup.config.mjs) or else Node will complain. The rollup() export is totally optional, its a re-export of defineCofig and used to provide type completions.

import { rollup, env, plugin } from "@brixtol/rollup-config";

export default rollup(
  {
    input: "src/file.ts",
    output:   {
      format: 'cjs',
      dir: 'package',
      sourcemap: env.is('dev', 'inline'), // Inline sourcemap in development else false
      interop: 'default'
    },
    plugins: env.if('div')(
      [
        plugin.commonjs(options: {}),
        plugin.ts(options: {}),
        // etc etc
      ]
    )(
      [
        plugin.terser()
      ]
    )
  }
);

Types are re-exported and provided for all plugins which support them. Rollup configuration files within our workspace.

What is the env.if() method?

This module provides exports from @brixtol/rollup-utils. The env.if() allows us to use single file for development and production bundles. When an --environment flag is passed with a of value of prod the plugins are concatenated, so first curried parameter is combined with the second curried parameter, which should both be an array list of plugins[].

The dev is deault, so running rollup -c -w results in:

env.if('dev')([ plugin.commonjs(), plugin.ts() ])([ plugin.terser() ])
// => [ commonjs(), ts() ]

If you run rollup -c --environment prod it results in:

env.if('dev')([ plugin.commonjs(), plugin.ts() ])([ plugin.terser() ])
// => [ commonjs(), ts(), terser() ]

Plugins

All plugins are available via the named plugin export. In addition to the plugins rollup's defineConfig function is exported as rollup namespace so configuration options have typings on the default export. Below is the complete list of included plugins:

Export Plugin Description
plugin.alias @rollup/plugin-alias Alias modules in a build
plugin.beep @rollup/plugin-beep Beeps when a build ends with errors
plugin.copy rollup-plugin-copy Copy files and folders, with glob support
plugin.commonjs @rollup/plugin-commonjs Convert CommonJS modules to ES Modules
plugin.del rollup-plugin-delete Delete files and folders
plugin.filesize rollup-plugin-filesize Show files size in the cli
plugin.html @rollup/plugin-html Creates HTML files to serve Rollup bundles
plugin.json @rollup/plugin-json Convert JSON files to ES Modules
plugin.livereload rollup-plugin-livereload Live Reload after changes
plugin.multi @rollup/plugin-multi-entry Use multiple entry points for a bundle.
plugin.polyfills rollup-plugin-node-polyfills Allows the node builtins to be required/imported
plugin.resolve @rollup/plugin-node-resolve Use the Node resolution algorithm
plugin.postcss rollup-plugin-postcss Seamless integration between Rollup and PostCSS
plugin.replace @rollup/plugin-replace Replace occurrences of a set of strings
plugin.ts @rollup/plugin-typescript Integration with Typescript.
plugin.ts2 rollup-plugin-typescript2 Alternative Rollup with TypeScript integration.
plugin.tspaths rollup-plugin-ts-paths Resolve import from paths in tsconfig.json
plugin.scss rollup-plugin-scss Process SASS and SCSS files
plugin.serve rollup-plugin-serve Serve a generated bundle
plugin.terser rollup-plugin-terser Minify generated es bundles using with terser

Optional Dependencies

The module includes several optional dependencies, one being Rollup itself. Ensure that if you are using a plugin you install any optional it might require.

Related

License

Licensed under MIT.


We open source!