A rollup plugin to make assets external but include them in the output.
Via npm
npm install --save-dev rollup-plugin-external-assetsVia yarn
yarn add -D rollup-plugin-external-assetsimport 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"),
],
};function externalAssets(
pattern: string | RegExp | (string | RegExp)[],
options: {
exclude?: string | RegExp | (string | RegExp)[],
include?: string | RegExp | (string | RegExp)[],
}
)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)$/])-
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"});After cloning this repo, ensure dependencies are installed by running:
npm installThen to build the final bundle:
npm run buildTo run tests:
npm testNote 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:warnCoverage 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.
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.