Registry / devops / fetch-write-webpack-plugin

fetch-write-webpack-plugin

JSON →
library1.1.0jsnpmunverified

Webpack plugin (v1.1.0) that fetches data from remote sources at build time and writes the results to static files. Designed for scenarios where data must be baked into the bundle during compilation, reducing runtime API calls. Provides retry logic, configurable output paths, and support for multiple fetch targets. Alternatives include custom webpack plugins or using CopyWebpackPlugin with external scripts, but this plugin simplifies the pattern.

npm install fetch-write-webpack-plugin
INSTALL
IMPORT
SIG · FETCH-WRITE-WEBPAC
F
fetch-write-webpack-plugin
devopsjavascriptv1.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

FetchWritePlugin
const FetchWritePlugin = require('fetch-write-webpack-plugin')
import FetchWritePlugin from 'fetch-write-webpack-plugin'
CommonJS only; no ES module export available.
default export
const FetchWritePlugin = require('fetch-write-webpack-plugin')
import { FetchWritePlugin } from 'fetch-write-webpack-plugin'
The plugin is exported as a single default export, not a named export.

Configures FetchWritePlugin in webpack.config.js to fetch JSON data from an API and write it to 'static/data.json' at build time.

const FetchWritePlugin = require('fetch-write-webpack-plugin'); module.exports = { entry: 'index.js', output: { path: __dirname + '/dist', filename: 'bundle.js' }, plugins: [ new FetchWritePlugin([ { fetchOpts: { url: 'https://api.example.com/data', retryOn: true, headers: { 'Content-Type': 'application/json' } }, output: { name: 'data', ext: 'json', basePath: './static' } } ]) ] };
Debug
Known issues
gotchaThe plugin uses node-fetch internally, which only supports Node.js. It will not work in browser-based bundling environments.
fix
Ensure the plugin is used in a Node.js environment (e.g., not in webpack-dev-server's in-memory compilation mode if that runs in browser).
affects: >=1.0.0
gotchaOutput basePath defaults to webpack's output path, but if omitted, files may be written to unexpected locations.
fix
Always specify an explicit basePath relative to your project root.
affects: >=1.0.0
gotchaThe plugin runs before compilation; fetched files are not watched. Changes in the fetched data will not trigger a rebuild.
fix
Use a manual rebuild or a different approach if live updates are needed.
affects: >=1.0.0
deprecatedThe 'retryOn' option is misspelled as 'retryOn' (not 'retryOn') in the documentation but the code expects 'retryOn'.
fix
Use 'retryOn' as the property name, not 'retryOn'.
affects: 1.0.0 - 1.1.0
Errors
Common errors & fixes
Error: Cannot find module 'node-fetch'
node-fetch is not automatically installed as a dependency; it is required at runtime.
fix
Install node-fetch as a dependency: npm install node-fetch
TypeError: fetch is not a function
The plugin expects node-fetch to be available globally or as a dependency, but it might be missing or version incompatible.
fix
Ensure node-fetch@2 is installed (the plugin has not been tested with v3).
Error: Cannot read property 'push' of undefined
The options parameter to FetchWritePlugin is not passed as an array, or the array is empty.
fix
Pass an array of config objects, e.g., new FetchWritePlugin([{...}])
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies
webpackrequiredpeer dependency required to function as a webpack plugin
Agent activity
2 hits · last 30 days
node
2
Resources
fetch-write-webpack-plugin — npm install fetch-write-webpack-plugin · libregistry