Registry / devops / webpack-copy-after-build-plugin

webpack-copy-after-build-plugin

JSON →
library1.0.1jsnpmunverified

webpack-copy-after-build-plugin is a Webpack plugin specifically designed to facilitate the integration of Webpack-generated build artifacts into legacy Ruby on Rails applications that utilize Sprockets. Its primary function is to copy compiled Webpack bundles to a specified directory within the Rails asset pipeline after the Webpack build process completes, making them directly accessible via Sprockets directives (e.g., `//= require`). The current stable version is 1.0.1. Given its very specific niche for Rails/Sprockets integration, its release cadence is likely infrequent and focused on maintenance or specific feature needs related to that ecosystem, rather than rapid general Webpack evolution. This plugin differentiates itself by addressing a particular pain point for hybrid Rails/Webpack applications, significantly reducing friction when gradually introducing Webpack into existing Rails projects by ensuring Webpack output can be easily consumed by Sprockets.

npm install webpack-copy-after-build-plugin
INSTALL
IMPORT
SIG · WEBPACK-COPY-AFTER
W
webpack-copy-after-build-plugin
devopsjavascriptv1.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.

WebpackCopyAfterBuildPlugin
const WebpackCopyAfterBuildPlugin = require('webpack-copy-after-build-plugin');
import WebpackCopyAfterBuildPlugin from 'webpack-copy-after-build-plugin';
The plugin is primarily distributed as CommonJS, aligning with older Webpack configurations often found in legacy Rails projects.
WebpackCopyAfterBuildPlugin
import WebpackCopyAfterBuildPlugin from 'webpack-copy-after-build-plugin';
While primarily CJS, modern bundlers can often transpile/import CommonJS modules into ESM contexts. This import style assumes such a setup.

Demonstrates how to configure webpack-copy-after-build-plugin to copy a Webpack-generated bundle into a Rails asset pipeline directory, making it accessible via Sprockets directives.

const path = require('path'); const WebpackCopyAfterBuildPlugin = require('webpack-copy-after-build-plugin'); // Create a directory in your asset pipeline first, e.g., `mkdir -p app/assets/javascripts/generated` module.exports = { context: __dirname, entry: { 'webpack-application-bundle': './client/bundles/webpack-application.js' }, output: { path: path.resolve(__dirname, 'public/assets'), filename: '[name]-[chunkhash].js' }, // Other webpack configuration like modules, resolve, etc. plugins: [ // Assuming another plugin for manifest generation, if needed // new WebpackSprocketsRailsManifestPlugin(), new WebpackCopyAfterBuildPlugin({ // Maps output bundle name to its desired destination path within the Rails asset pipeline 'webpack-application-bundle': path.resolve(__dirname, 'app/assets/javascripts/generated/webpack-application-bundle.js') }) ] }; // client/bundles/webpack-application.js (example content) // alert("Howdy, I'm a Webpack Javascript file!"); // app/assets/javascripts/application.js (example Sprockets directive) // //= require ./generated/webpack-application-bundle
Debug
Known issues
gotchaThe plugin expects the destination directories to exist. It does not automatically create them. Failure to create the target directory (e.g., `app/assets/javascripts/generated`) will result in copy errors.
fix
Ensure all destination paths specified in the plugin configuration (`new WebpackCopyAfterBuildPlugin({ 'source': 'destination' })`) point to pre-existing directories. Use `mkdir -p` or similar commands as part of your build setup.
affects: >=1.0.0
gotchaThe `absoluteMappingPaths` option (defaulting to `false`) determines how destination paths are interpreted. If `false`, paths are relative to the Webpack output `path`. If `true`, they are treated as absolute paths. Misunderstanding this can lead to files being copied to incorrect locations or not found.
fix
Carefully define your destination paths. If providing an absolute path in the mapping, explicitly set `absoluteMappingPaths: true` in the plugin options, or use `path.resolve` as shown in the quickstart for clarity.
affects: >=1.0.0
breakingThis plugin was designed for older Webpack versions (likely Webpack 2-4, given its `require` syntax and age). While it might function with Webpack 5+, full compatibility and optimal behavior are not guaranteed without thorough testing. Newer Webpack features or breaking changes in plugin APIs might cause unexpected issues.
fix
If encountering issues with Webpack 5+, review the Webpack plugin API documentation for your version. Consider checking for community forks or alternative solutions if maintaining compatibility becomes problematic. Thorough testing is recommended for newer Webpack versions.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: WebpackCopyAfterBuildPlugin is not a constructor
The plugin was called as a function instead of being instantiated with the `new` keyword.
fix
Ensure you are using `new WebpackCopyAfterBuildPlugin({...})` when adding it to your webpack `plugins` array.
Error: ENOENT: no such file or directory, copyFile '<webpack_output_path>/bundle.js' -> '<destination_path>/bundle.js'
The destination directory specified in the plugin's configuration does not exist.
fix
Manually create the destination directory before running Webpack, or include a script step to create it (e.g., `mkdir -p path/to/destination`) in your build process.
Error: A plugin must be an instance of a class. Instead got: function WebpackCopyAfterBuildPlugin()
This error typically indicates that Webpack is trying to treat a non-class as a plugin, often due to incorrect CommonJS `require` usage when Webpack expects an ES module or a specific class structure.
fix
Verify that `const WebpackCopyAfterBuildPlugin = require('webpack-copy-after-build-plugin');` is the correct way to import the plugin. Ensure your `webpack.config.js` environment (Node.js version, Babel transpilation) is compatible with the plugin's export format.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
webpackrequiredPeer dependency as it's a webpack plugin.
webpack-sprockets-rails-manifest-pluginoptionalCommonly used in conjunction for Rails integration, as shown in the example configuration.
Agent activity
5 hits · last 30 days
node
4
Resources
webpack-copy-after-build-plugin — npm install webpack-copy-after-build-plugin · libregistry