Add sprockets metadata to webpack stats for asset manifest generation.
MIT License
This is a webpack plugin which creates a mapping for generating a sprockets/rails compatible asset manifest.
This plugin can:
stats.toJson()
, allowing you tocompiliation
and into stats.toJson()
.npm install sprockets-stats-webpack-plugin --save-dev
// 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.
customStatsKey
: This is the parent key the mapping is saved to. If yousprockets
.ignore
: This is a regex to skip adding custom stats data for assets where(/\.(gz|html)$/i)
.outputAssetsPath
: Absolute path to where the assets are built to.path.join(process.cwd(), 'build', 'assets')
.sourceAssetsPath
: Absolute path to where the source assets are located.images/picture.jpeg
.path.join(process.cwd(), 'src', 'assets')
.mappings
: (Optional) Array of mapping objects for customizing the logical[]
test
: Regex for matching source files using their absolute paths.logicalPath
: Pattern using Webpack placeholders for renaming the logicalcontext
: Absolute path to a context directory for the sources matched[path]
placeholder inlogicalPath
to create logical paths relative to an arbitrary directory.sourceAssetsPath
saveAs
: Absolute path to where to save the output to.path.join(process.cwd(), 'build', 'sprockets-manifest.json')
write
: Boolean option, of whether to write the stats file or not.true
resultsKey
: Where to save the results to in webpack's compilation
object.__RESULTS_SPROCKETS
MIT.