save-remote-file-webpack-plugin

raw JSON →
1.1.0 verified Sat Apr 25 auth: no javascript maintenance

Webpack 4 plugin that downloads remote files (e.g., analytics.js) during the build process and saves them locally with content hashes for cache busting. Version 1.1.0 is the latest stable release, offering a `hash` option to toggle content hashing. It integrates with `manifest-webpack-plugin` by emitting downloaded files. Designed for developers needing to self-host external scripts without manual downloads or build hooks.

error TypeError: SaveRemoteFilePlugin is not a constructor
cause Using named import via destructuring, which returns undefined.
fix
Use const SaveRemoteFilePlugin = require('save-remote-file-webpack-plugin');
error Error: options must be an array
cause Passing a single object instead of an array to the constructor.
fix
Wrap option in array: new SaveRemoteFilePlugin([{ url: '...', filepath: '...' }])
error Error: Cannot find module 'download'
cause Missing dependency 'download' which is required at runtime.
fix
Install the 'download' package: npm install download
breaking In version 1.0.0, files were saved without content hashes. Upgrade to >=1.0.1 for hash support.
fix Update to version 1.0.1 or later: npm install save-remote-file-webpack-plugin@latest
gotcha The plugin expects an array of option objects, even for a single file. Passing an object will cause an error.
fix Wrap single config in an array: new SaveRemoteFilePlugin([{ url: '...', filepath: '...' }])
gotcha The imported module is the default export, not a named export. Destructuring will result in undefined.
fix Use require('save-remote-file-webpack-plugin') directly, not { SaveRemoteFilePlugin }.
deprecated Plugin is designed for webpack 4 only; not guaranteed to work with webpack 5 due to internal API changes.
fix Consider using webpack 5 compatible alternatives or migrate to fetch in build scripts.
npm install save-remote-file-webpack-plugin
yarn add save-remote-file-webpack-plugin
pnpm add save-remote-file-webpack-plugin

Shows how to require and configure the plugin in a webpack 4 config, downloading one remote file with content hashing enabled.

const SaveRemoteFilePlugin = require('save-remote-file-webpack-plugin');

module.exports = {
  entry: './src/index.js',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'bundle.js',
  },
  plugins: [
    new SaveRemoteFilePlugin([
      {
        url: 'https://example.com/external.js',
        filepath: 'js/external.js',
        hash: true,
      },
    ]),
  ],
};