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-pluginVerified import paths — ran on the pinned version, not inferred.
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.
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.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.
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.
Ensure you are using `new WebpackCopyAfterBuildPlugin({...})` when adding it to your webpack `plugins` array.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.
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.