mikechau / sprockets-stats-webpack-plugin

Add sprockets metadata to webpack stats for asset manifest generation.
MIT License
6 stars 3 forks source link

sprockets-stats-webpack-plugin

npm version Build Status Dependency Status devDependency Status

This is a webpack plugin which creates a mapping for generating a sprockets/rails compatible asset manifest.

This plugin can:

Install

npm install sprockets-stats-webpack-plugin --save-dev

Usage

// Your webpack config
var SriStatsPlugin = require('sri-stats-webpack-plugin');
var SprocketsStatsPlugin = require('sprockets-stats-webpack-plugin');

var config = {
  plugins: [
    new SriStatsPlugin({
      algorithm: 'sha512',
      customStatsKey: 'rails',
      assetKey: 'integrity'
    }),

    new SprocketsStatsPlugin({
      customStatsKey: 'rails',
      ignore: (/\.(gz|html)$/i),
      outputAssetsPath: path.join(__dirname, 'build', 'assets'),
      sourceAssetsPath: path.join(__dirname, 'src', 'assets'),
      mappings: [
        {
          test: 'src\/assets\/images',
          logicalPath: '[path][name].[ext]',
          context: path.join(process.cwd(), 'src', 'assets', 'images')
        },
        {
          test: 'src\/assets\/videos',
          logicalPath: '[path][name].[ext]',
          context: path.join(process.cwd(), 'src', 'assets', 'videos')
        }
      ],
      saveAs: path.join(__dirname, 'build', 'sprockets-manifest.json'),
      write: true,
      resultsKey: '__RESULTS_SPROCKETS'
    })
 ]
};

module.exports = config;

If you are using this plugin with SriStatsWebpackPlugin, it must go before this plugin. Order matters.

Configuration

License

MIT.