webpack-config-spaceship
Version:
Webpack config to get a project off the ground fast.
34 lines (28 loc) • 861 B
JavaScript
const path = require('path');
const mapValues = require('lodash.mapvalues');
const groupBy = require('lodash.groupby');
const LEADING_DOT_REGEXP = /^\./;
function defaultFilter() {
return true;
}
function identity(value) {
return value;
}
function getAssetsFromStats(webpackStats) {
const stats = webpackStats.toJson ? webpackStats.toJson() : webpackStats;
return mapValues(stats.assetsByChunkName, chunkAssets => {
let assets = Array.isArray(chunkAssets) ? chunkAssets : [chunkAssets];
assets = assets.filter(assetName => {
if (assetName.substr(-4) === '.map') {
return true;
}
return assets.indexOf(`${assetName}.map`) !== -1;
});
return groupBy(assets, filePath => path.extname(filePath).replace(LEADING_DOT_REGEXP, ''));
});
}
module.exports = {
defaultFilter,
identity,
getAssetsFromStats,
};