Simple asset to json webpack plugin
{
"assets": {
"js": [{
"name": "polyfills",
"files": ["polyfills.a4a96aebc315cd042a48.bundle.js"]
}, {
"name": "vendor",
"files": ["vendor.a4a96aebc315cd042a48.bundle.js"]
}, {
"name": "app",
"files": ["app.a4a96aebc315cd042a48.bundle.js"]
}],
"css": [{
"name": "app",
"files": ["app.09bff5466d500a2adfef92c1c2867e23.css"]
}]
}
}
npm install json-asset-webpack-plugin --save-dev
var JSONAssetWebpackPlugin = require("json-asset-webpack-plugin");
new JSONAssetWebpackPlugin( {config: optional} )
config.out
(optional)- string: default: "assets.json"
config.chunksSortMode
(optional)- Function:
Array.sort
used to sort bothjs
andcss
files https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/sort - Object:
{ js: Array.sort function (optional), css: Array.sort function (optional) }
- Function:
config.beforeWrite
(optional)- Function
(outPath, assetsObj, callback)
- callback must be called with 2 arguments
(outPath, assetsObj)
withinbeforeWrite()
in order for the plugin to write assets file;
- callback must be called with 2 arguments
- Function
new JSONAssetWebpackPlugin({
chunksSortMode: function(a, b) {
// thanks to @jantimon https://github.com/jantimon/html-webpack-plugin/issues/140#issuecomment-263927464
var order = ["polyfills", "vendor", "app"];
return order.indexOf(a.name) - order.indexOf(b.name);
}
})
new JSONAssetWebpackPlugin({
beforeWrite: function(outPath, assetsObj, callback) {
// manipulate outPath/assetsObj if needed
callback(outPath, assetsObj); // must be called to write the file
}
})
- fork this repository
- add changes
- add/modify tests (index.spec or similar)
- run
npm test
(all green) - create pull request