A Rollup plugin which downloads resources of bare asset URLs and replaces them with local URLs.
Attention: Remote asset detection is achieved through simple string replacement, not via the Rollup module graph.
This plugin requires Node v14+ and Rollup v1.20+.
The following dependencies need to be installed:
npm install --save-dev got@12 magic-string@0.26 rev-hash@4 @rollup/pluginutils@4
Add to rollup config:
import extractRemoteAssets from './plugin-extract-remote-assets.js'
export default {
plugins: [
extractRemoteAssets({
// A string, a regex, or an array thereof
source: /https:\/\/example.com\/([a-z0-9/._~-]+).(jpe?g|png|gif|webp)/gi
})
]
}
Type: string | RegExp | Array<string | RegExp>
The URL(s) to download and replace.
Type: string
Default: "extracted-assets"
Directory (relative to the output directory) to copy assets to.
Type: string | string[]
Default: undefined
A picomatch pattern, or array of patterns, which specifies the files in the build the plugin should ignore. By default no files are ignored.
Type: string | string[]
Default: undefined
A picomatch pattern, or array of patterns, which specifies the files in the build the plugin should operate on. By default all files are targeted.
Type: boolean
Default: true
Whether to reflect source code changes in the source map.