README
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(
include?: string | RegExp | (string | RegExp)[],
exclude?: string | RegExp | (string | RegExp)[],
options?: { resolve?: string | false | null },
);
include / exclude
string | RegExp | (string | RegExp)[]
A valid picomatch pattern, or array of patterns.
If include
is omitted or has zero length, all imports will be considered as assets.
Otherwise, an import path must match one or more of the include
patterns,
and must not match any of the exclude
patterns.
Note: patterns that include windows paths are normalized to be valid picomatch patterns.
import path from "path";
// Operate on images located in the ./assets directory.
externalAssets("assets/**/*.jpg");
// Operate on images located in the ./assets directory.
// and all stylesheet files.
externalAssets(["assets/**/*.{jpg,png}", /\.(css|scss)$/]);
// Operate on all assets except text files.
externalAssets("assets/**/*", "**/*.txt");
// Operate on all assets except text files.
// `__dirname` is the pattern's base dir instead of `process.cwd()`.
externalAssets(path.resolve(__dirname, "assets/**/*"), "**/*.txt");
options
resolve
{string | false | null}
: Optionally resolves the patterns against a directory other thanprocess.cwd()
. If astring
is specified, then the value will be used as the base directory. Relative paths will be resolved againstprocess.cwd()
first. Iffalse
, then the patterns will not be resolved against any directory.
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
Note that rollup may emit warnings for unspecified options, or for some other reasons.
I made sure they are ignored with the ROLLUP_WARNINGS
environment variable 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.
To run tests and update snapshots, pass the -u
flag to jest through the test
(or test:warn
) npm script:
npm test -- -u
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.