/rollup-plugin-rebase

The Rollup Rebase Plugin copies static assets as required from your JavaScript code to the destination folder and adjusts the references in there to point to the new location.

Primary LanguageJavaScriptApache License 2.0Apache-2.0

Rollup Rebase
Sponsored by Version Downloads Build Status

The Rollup Rebase Plugin copies static assets as required from your JavaScript code to the destination folder and adjusts the references in there to point to the new location. It also respects assets referenced from your CSS/SCSS files.

Features

  • Copies over asset files references from JavaScript into the given output folder.
  • Adjust asset references in the output JavaScript files to map to the relative new location.
  • Transforms CSS files to inline all includes from @import via PostCSS Import into the origin files.
  • Detects and processes assets referenced from both, JavaScript and CSS.
  • Renames all assets based on their hash (XXHash + Base62) so that conflicts are automatically eliminated while producing a flat output structure.
  • Supports normal CSS, but also SugarSS, SCSS and Sass via the standard PostCSS parser plugins.

Comparison

The plugin is meant as a tool for preparing a library for being published. In this it differs from plugins like Rollup URL Plugin as it is designed for usage in libraries and not for applications. The output of this plugin can be used by tools like Webpacks File Loader, URL Loader or the already mentioned Rollup URL Plugin.

Installation

$ npm install --save-dev rollup-plugin-rebase

or

$ yarn add --dev rollup-plugin-rebase

Usage

You can configure Rollup Rebase as part of your Rollup configuration. This can be either done in a rollup.config.js or by scripting using the Rollup API:

import { rollup } from "rollup"
import rebasePlugin from "rollup-plugin-rebase"

async function config() {
  const bundle = await rollup({
    input: "./src/index.js",
    plugins: [rebasePlugin()]
  })

  await bundle.write({
    dest: "./lib/index.js"
  })
}

config()

Options (all optional)

  • assetFolder: When set assets are placed inside a sub folder with that name.
  • keepName: If true, generated filenames will be ${filename}~${hash}.${ext} instead of just ${hash}.${ext}
  • verbose: If true, increases log level
  • include: Standard include option for rollup plugins.
  • exclude: Standard exclude option for rollup plugins.

Copyright

Logo of Sebastian Software GmbH, Mainz, Germany

Copyright 2016-2022
Sebastian Software GmbH