rollup-plugin-external-assets
TypeScript icon, indicating that this package has built-in type declarations

4.1.1 • Public • Published

npm npm build codecov MIT license

rollup-plugin-external-assets

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.

Installation

Via npm

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

Via yarn

yarn add -D rollup-plugin-external-assets

Usage

Assuming a src/index.js exists and contains code like the following:

import logo from "../assets/logo.png";

console.log(logo);

Create a rollup.config.js configuration file and import the plugin:

import { externalAssets } from "rollup-plugin-external-assets";

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

Then call rollup either via the CLI or the API.

Once the bundle is executed, you end up with a dist directory like the following:

dist directory structure

With dist/index.js containing:

"use strict";

var logo = require("./assets/logo-0c6cee7b.png");
console.log(logo);

Options

To tailor the plugin behavior to your needs, you can pass a configuration object as the argument:

include

• Type: string | RegExp | (string | RegExp)[]

A pattern, or array of patterns, to match files the plugin should operate on.

exclude

• Type: string | RegExp | (string | RegExp)[]

A pattern, or array of patterns, to match files the plugin should ignore.

resolve

• Type: string
• Default: process.cwd()

The value will be used as the base directory for resolving patterns.

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

To run tests:

npm test

To run tests with coverage report:

npm run test:coverage

Coverage report is located in tests/coverage.

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

Package Sidebar

Install

npm i rollup-plugin-external-assets

Weekly Downloads

1,364

Version

4.1.1

License

MIT

Unpacked Size

23.4 kB

Total Files

9

Last publish

Collaborators

  • soufyakoub