Skip to content

Commit

Permalink
Merge pull request #175 from webpack-contrib/174-modules-in-chunks
Browse files Browse the repository at this point in the history
Collect modules from `chunks` array
  • Loading branch information
th0r authored May 9, 2018
2 parents 709eee7 + 9b882f8 commit bf86048
Show file tree
Hide file tree
Showing 4 changed files with 633 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/analyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ function getViewerData(bundleStats, bundleDir, opts) {
}
}

const modules = getBundleModules(bundleStats);
const assets = _.transform(bundleStats.assets, (result, statAsset) => {
const asset = result[statAsset.name] = _.pick(statAsset, 'size');

Expand All @@ -76,7 +77,7 @@ function getViewerData(bundleStats, bundleDir, opts) {
}

// Picking modules from current bundle script
asset.modules = _(bundleStats.modules)
asset.modules = _(modules)
.filter(statModule => assetHasModule(statAsset, statModule))
.each(statModule => {
if (parsedModules) {
Expand Down Expand Up @@ -107,6 +108,16 @@ function readStatsFromFile(filename) {
);
}

function getBundleModules(bundleStats) {
return _(bundleStats.chunks)
.map('modules')
.concat(bundleStats.modules)
.compact()
.flatten()
.uniqBy('id')
.value();
}

function assetHasModule(statAsset, statModule) {
return _.some(statModule.chunks, moduleChunk =>
_.includes(statAsset.chunks, moduleChunk)
Expand Down
8 changes: 8 additions & 0 deletions test/analyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ describe('Analyzer', function () {
await expectValidReport();
});

it('should support stats files with modules inside `chunks` array', async function () {
generateReportFrom('with-modules-in-chunks/stats.json');
const chartData = await getChartData();
expect(chartData).to.containSubset(
require('./stats/with-modules-in-chunks/expected-chart-data')
);
});

it('should support bundles with invalid dynamic require calls', async function () {
generateReportFrom('with-invalid-dynamic-require.json');
await expectValidReport({ statSize: 136 });
Expand Down
59 changes: 59 additions & 0 deletions test/stats/with-modules-in-chunks/expected-chart-data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
module.exports = [
{
'label': 'runtime.6afe30102d8fe7337431.js',
'statSize': 0,
'groups': []
},
{
'label': 'polyfills.2903ad11212d7d797800.js',
'statSize': 101,
'groups': [
{
'label': 'node_modules',
'path': './node_modules',
'statSize': 101,
'groups': [
{
'label': 'core-js',
'path': './node_modules/core-js',
'statSize': 101,
'groups': [
{
'label': 'modules',
'path': './node_modules/core-js/modules',
'statSize': 101,
'groups': [
{
'id': '+rLv',
'label': '_html.js',
'path': './node_modules/core-js/modules/_html.js',
'statSize': 101
}
]
}
]
}
]
}
]
},
{
'label': 'main.e339f68cc77f07c43589.js',
'statSize': 160,
'groups': [
{
'label': 'src',
'path': './src',
'statSize': 160,
'groups': [
{
'id': 'crnd',
'label': '$$_lazy_route_resource lazy namespace object',
'path': './src/$$_lazy_route_resource lazy namespace object',
'statSize': 160
}
]
}
]
}
];
Loading

0 comments on commit bf86048

Please sign in to comment.