Webpack Copy After Build Plugin

1.0.1 · maintenance · verified Tue Apr 21

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.

Common errors

Warnings

Install

Imports

Quickstart

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

view raw JSON →