Registry / web-framework / copy-asset-in-memory-webpack-plugin

copy-asset-in-memory-webpack-plugin

JSON →
library4.0.1jsnpmunverified

Webpack 5 plugin to copy processed assets while the compilation is still in memory, before they are written to disk. Version 4.0.1 is the latest stable, with a history of breaking changes aligning with webpack 5. It allows filtering by test/include/exclude, renaming via `to`, transforming content, and optionally deleting original assets. Unlike copy-webpack-plugin which copies from filesystem to output, this plugin copies assets already in webpack's compilation graph. Requires webpack ^5.20.0 and Node >=12.13. Ships TypeScript types.

npm install copy-asset-in-memory-webpack-plugin
INSTALL
IMPORT
SIG · COPY-ASSET-IN-MEMO
C
copy-asset-in-memory-webpack-plugin
web-frameworkjavascriptv4.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

CopyAssetInMemoryPlugin
const CopyAssetInMemoryPlugin = require('copy-asset-in-memory-webpack-plugin');
import CopyAssetInMemoryPlugin from 'copy-asset-in-memory-webpack-plugin';
This package does not export an ESM default; use CommonJS require in webpack config. For ESM usage, use dynamic import or convert config to .mjs with createRequire.
CopyAssetInMemoryPlugin
import CopyAssetInMemoryPlugin from 'copy-asset-in-memory-webpack-plugin';
const { CopyAssetInMemoryPlugin } = require('copy-asset-in-memory-webpack-plugin');
TypeScript types are exported as default: `export default class`. Named import fails in CJS because the only export is a default.
type CopyAssetInMemoryPluginOptions
import type { CopyAssetInMemoryPluginOptions } from 'copy-asset-in-memory-webpack-plugin';
import { CopyAssetInMemoryPluginOptions } from 'copy-asset-in-memory-webpack-plugin';
Options type is a named export in TypeScript. For value imports, use default. Type-only import avoids runtime errors.

Shows CommonJS usage in webpack.config.js, copying .js assets to a 'scripts' subfolder in memory.

// webpack.config.js const CopyAssetInMemoryPlugin = require('copy-asset-in-memory-webpack-plugin'); module.exports = { entry: './src/index.js', output: { path: path.resolve(__dirname, 'dist'), filename: 'bundle.js', }, plugins: [ new CopyAssetInMemoryPlugin({ test: /\.js$/, to: (fileName) => `scripts/${fileName}`, }), ], };
Debug
Known issues
breakingv4.0.0 dropped support for webpack 4. Upgrade to webpack 5 to use this version.
fix
Upgrade webpack to ^5.20.0. If stuck on webpack 4, use v3.x.
affects: >=4.0.0
gotchaAssets cannot be copied outside the output directory. Attempting to do so will silently fail or cause undefined behavior.
fix
Ensure the `to` option produces paths relative to the output directory. Do not use absolute paths or '..'.
affects: *
gotchadeleteOriginalAssets: true deletes the asset's source map as well, because source maps are separate assets that share the same base filename.
fix
If you need source maps, either disable deleteOriginalAssets or manually copy the source map before deletion.
affects: *
deprecatedThe `stage` option default is Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE. In future webpack versions, this stage might be removed or behave differently.
fix
Explicitly set stage to Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL for forward compatibility.
affects: >=4.0.0
Errors
Common errors & fixes
Cannot find module 'copy-asset-in-memory-webpack-plugin'
Package not installed or webpack config not resolving node_modules correctly.
fix
Run `npm install -D copy-asset-in-memory-webpack-plugin` and ensure your webpack config is in a directory where node_modules can be resolved.
TypeError: CopyAssetInMemoryPlugin is not a constructor
Incorrect import style; likely using ESM default import in a CJS context, or named import where default was expected.
fix
Use `const CopyAssetInMemoryPlugin = require('copy-asset-in-memory-webpack-plugin');` in CommonJS, or `import CopyAssetInMemoryPlugin from 'copy-asset-in-memory-webpack-plugin';` in ESM (with appropriate configuration).
Error: Hook is not defined for compilation stage
Invalid `stage` value; webpack removed or renamed the stage constant.
fix
Use `Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE` (default) or another valid stage from webpack's Compilation object.
Webpack 5 requires node >=10.13.0 but copy-asset-in-memory-webpack-plugin requires >=12.13
Incompatible Node.js version installed (too low).
fix
Upgrade Node.js to version >=12.13.
Upgrade
Version history
4.0.1latest on npm
Audit
Dependencies
webpackrequiredpeer dependency: requires webpack 5.20+
Agent activity
4 hits · last 30 days
node
4
Resources
copy-asset-in-memory-webpack-plugin — npm install copy-asset-in-memory-webpack-plugin · libregistry