sprockets-stats-webpack-plugin
This is a webpack plugin which creates a mapping for generating a sprockets/rails compatible asset manifest.
This plugin can:
- Write a compatible sprockets asset manifest.
- Inject sprockets asset data into webpack's
stats.toJson()
, allowing you to further consume the data with other stat plugins. - Inject the results into webpack's
compiliation
and intostats.toJson()
.
Install
npm install sprockets-stats-webpack-plugin --save-dev
Usage
// Your webpack configvar SriStatsPlugin = ;var SprocketsStatsPlugin = ; var config = plugins: algorithm: 'sha512' customStatsKey: 'rails' assetKey: 'integrity' customStatsKey: 'rails' ignore: /\.$/i outputAssetsPath: path sourceAssetsPath: path saveAs: path write: true resultsKey: '__RESULTS_SPROCKETS' ; moduleexports = config;
If you are using this plugin with SriStatsWebpackPlugin, it must go before this plugin. Order matters.
Configuration
customStatsKey
: This is the parent key the mapping is saved to. If you plan to use this with the SriStatsWebpackPlugin, you should make sure they use the same keys. Default:sprockets
.ignore
: This is a regex to skip adding custom stats data for assets where it would not be relevant to generate sprockets manifest data for. Default:(/\.(gz|html)$/i)
.outputAssetsPath
: Absolute path to where the assets are built to. Default:path.join(process.cwd(), 'build', 'assets')
.sourceAssetsPath
: Absolute path to where the source assets are located. Helps the plugin build mappings to files likeimages/picture.jpeg
. Default:path.join(process.cwd(), 'src', 'assets')
.saveAs
: Absolute path to where to save the output to. Default:path.join(process.cwd(), 'build', 'sprockets-manifest.json')
write
: Boolean option, of whether to write the stats file or not. Default:true
resultsKey
: Where to save the results to in webpack'scompilation
object. Default:__RESULTS_SPROCKETS
License
MIT.