Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sibiraj-s/copy-asset-in-memory-webpack-plugin
Copy assets in webpack memory
https://github.com/sibiraj-s/copy-asset-in-memory-webpack-plugin
copy-webpack-plugin webpack webpack-plugin
Last synced: about 1 month ago
JSON representation
Copy assets in webpack memory
- Host: GitHub
- URL: https://github.com/sibiraj-s/copy-asset-in-memory-webpack-plugin
- Owner: sibiraj-s
- License: mit
- Created: 2020-11-07T16:16:17.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-09-11T12:22:11.000Z (5 months ago)
- Last Synced: 2024-12-24T12:44:19.306Z (about 2 months ago)
- Topics: copy-webpack-plugin, webpack, webpack-plugin
- Language: JavaScript
- Homepage: https://npm.im/copy-asset-in-memory-webpack-plugin
- Size: 1.15 MB
- Stars: 1
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# copy-asset-in-memory-webpack-plugin
[](https://github.com/sibiraj-s/copy-asset-in-memory-webpack-plugin/actions)
[](https://github.com/sibiraj-s/copy-asset-in-memory-webpack-plugin)
[](https://npmjs.com/copy-asset-in-memory-webpack-plugin)
[](https://npmjs.com/copy-asset-in-memory-webpack-plugin)
[](https://webpack.js.org/)> Copy assets in webpack memory
## Getting Started
### Installation
```bash
npm i -D copy-asset-in-memory-webpack-plugin
# or
yarn add --dev copy-asset-in-memory-webpack-plugin
```### Usage
```js
// webpack.config.js
const CopyAssetInMemoryPlugin = require("copy-asset-in-memory-webpack-plugin");module.exports = {
plugins: [
new CopyAssetInMemoryPlugin({
test: /.js$/,
to: "js",
}),
],
};
```### Options
#### test
Include all assets that pass test assertion
Type: `String|RegExp|Array`. Default: `undefined`
#### include
Include all assets matching any of these conditions
Type: `String|RegExp|Array`. Default: `undefined`
#### exclude
Exclude all assets matching any of these conditions
Type: `String|RegExp|Array`. Default: `undefiend`
#### stage
Refer https://webpack.js.org/api/compilation-hooks/#processassets for more info.
```js
// webpack.config.js
const { Compilation } = require("webpack");
const CopyAssetInMemoryPlugin = require("copy-asset-in-memory-webpack-plugin");module.exports = {
plugins: [
new CopyAssetInMemoryPlugin({
test: /.js$/,
stage: Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE, // Default
to: (fileName) => `${js}/filename`,
}),
],
};
```#### to
Asset destination, allows to modify the file path.
Type: `Function | string`. Default: `undefined`
```js
// webpack.config.js
const CopyAssetInMemoryPlugin = require("copy-asset-in-memory-webpack-plugin");module.exports = {
plugins: [
new CopyAssetInMemoryPlugin({
test: /.js$/,
to: (fileName) => `${js}/filename`, // copies all files into `js` folder
}),
new CopyAssetInMemoryPlugin({
test: /.svg$/,
to: "assets", // copies all files into `assets` folder
}),
],
};
```#### transform
Allows to modify the file contents.
Type: `Function`. Default: `undefined`
```js
// webpack.config.js
const CopyAssetInMemoryPlugin = require("copy-asset-in-memory-webpack-plugin");module.exports = {
plugins: [
new CopyAssetInMemoryPlugin({
test: /.js$/,
to: (fileName) => `${js}/filename`,
// The `content` argument is a [`Buffer`](https://nodejs.org/api/buffer.html) object
// it could be converted to a `String` to be processed using `content.toString()`
transform: (content) => "newContent",
}),
],
};
```#### deleteOriginalAssets
Whether to delete the original assets or not.
Type: `boolean`. Default: `false`
### Caveats
- assets cannot be copied outside output directory
- deleting an asset via `deleteOriginalAssets` will also delete its sourcemap### Related Plugins
- [replace-asset-name-webpack-plugin](https://github.com/sibiraj-s/replace-asset-name-webpack-plugin)