Skip to content

A rollup plugin to make assets external, they will not be added to the bundling pipeline, but they will still be included in the final output.

License

Notifications You must be signed in to change notification settings

recursive-beast/rollup-plugin-external-assets

Repository files navigation

npm npm Build Status codecov MIT license

rollup-plugin-external-assets

A rollup plugin to make assets external but include them in the output.

Installation

Via npm

npm install --save-dev rollup-plugin-external-assets

Via yarn

yarn add -D rollup-plugin-external-assets

Usage

import nodeResolve from "@rollup/plugin-node-resolve";
import externalAssets from "rollup-plugin-external-assets";

export default {
	input: "src/index.js",
	output: {
		file: "dist/index.js",
		format: "es",
		sourcemap: true,
	},
	plugins: [
		nodeResolve(),
		externalAssets("assets/*.png"),
	],
};

API

function externalAssets(
	pattern: string | RegExp | (string | RegExp)[],
	options: {
		exclude?: string | RegExp | (string | RegExp)[],
		include?: string | RegExp | (string | RegExp)[],
	}
)

pattern

A picomatch pattern, or array of patterns, which correspond to assets the plugin should operate on.

// Process imports that reference images in the <working dir>/assets directory.
externalAssets("assets/**/*.jpg");
// Process imports that reference images in the <working dir>/assets directory, and all stylesheet files.
externalAssets(["assets/**/*.{jpg,png}", /\.(css|scss)$/])

options

  • include?: A picomatch pattern, or array of patterns, which correspond to modules the plugin should operate on. By default all modules are targeted.

  • exclude?: A picomatch pattern, or array of patterns, which correspond to modules the plugin should ignore. By default no modules are ignored.

// Don't process imports from js modules in src/exclude.
externalAssets("assets/**/*", {exclude: "src/exclude/*.js"});
// Process imports only from js modules in src/include.
externalAssets("assets/**/*", {include: "src/include/*.js"});
// Process imports from js modules in src/include, but not from js modules in src/exclude.
externalAssets("assets/**/*", {include: "src/include/*.js", exclude: "src/exclude/*.js"});

Contributing

Prerequisites

Getting Started

After cloning this repo, ensure dependencies are installed by running:

npm install

Then to build the final bundle:

npm run build

Tests

⚠️ This plugin was only tested for static imports ⚠️

To run tests:

npm test

Note that rollup may emit warnings for unspecified options, or for some other reasons. I made sure they are ignored with the no-rollup-warnings flag in the npm test script.

If you want to see all the warnings when running tests, use this command instead:

npm run test:warn

Coverage report is located in tests/coverage. you might want to review it in your browser, and for example, write tests for non-covered blocks, or remove them if they're useless.

Commiting changes

Please follow the conventional commits specification, because semantic-release is used to automate the whole package release workflow including: determining the next version number, generating the release notes and publishing the package.

License

MIT

About

A rollup plugin to make assets external, they will not be added to the bundling pipeline, but they will still be included in the final output.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 3

  •  
  •  
  •