Skip to content

Commit

Permalink
fix #1
Browse files Browse the repository at this point in the history
  • Loading branch information
wayou committed Aug 20, 2021
1 parent eb66544 commit 2bb1035
Show file tree
Hide file tree
Showing 4 changed files with 634 additions and 573 deletions.
20 changes: 13 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ Outputs exactly what went into each chunk

The code is taken from the [webpack documentation](https://github.com/webpack/docs/wiki/plugins#after-optimize-chunk-assetschunks-chunk)


I find this so useful for debugging. But there's no package in the npm.


### install

```
Expand All @@ -20,13 +18,21 @@ npm i -D print-chunks-plugin
### usage

```js
var PrintChunksPlugin = require('print-chunks-plugin');
var PrintChunksPlugin = require("print-chunks-plugin");
var webpackConfig = {
entry: 'index.js',
entry: "index.js",
output: {
path: __dirname + '/dist',
filename: 'index_bundle.js'
path: __dirname + "/dist",
filename: "index_bundle.js",
},
plugins: [new PrintChunksPlugin()]
plugins: [new PrintChunksPlugin()],
// or with option:
plugins: [new PrintChunksPlugin({ showFull: true })],
};
```

### Options

- `showFull`: stringify the result to get rid of the 100 array output limit of `console.log`, [learn more](https://stackoverflow.com/questions/41669039/dumping-whole-array-console-log-and-console-dir-output-num-more-items)
- type: `bool`
- default: `false`
40 changes: 23 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
/**
* outputs exactly what went into each chunk
*
*
* code is taken from the webpack documentation
* https://github.com/webpack/docs/wiki/plugins#after-optimize-chunk-assetschunks-chunk
*/

var PrintChunksPlugin = function() {};
PrintChunksPlugin.prototype.apply = function(compiler) {
compiler.plugin('compilation', function(compilation, params) {
compilation.plugin('after-optimize-chunk-assets', function(chunks) {
console.log(
chunks.map(function(c) {
return {
id: c.id,
name: c.name,
includes: c.modules.map(function(m) {
return m.request;
})
};
})
);
});
var util = require("util");

var PrintChunksPlugin = function (options = {}) {
this.options = options;
};
PrintChunksPlugin.prototype.apply = function (compiler) {
var showFull = this.options.showFull;
compiler.plugin("compilation", function (compilation, params) {
compilation.plugin("after-optimize-chunk-assets", function (chunks) {
var items = chunks.map(function (c) {
return {
id: c.id,
name: c.name,
includes: c.modules.map(function (m) {
return m.request;
}),
};
});
console.log(
showFull ? util.inspect(items, { maxArrayLength: null }) : items
);
});
});
};

module.exports = PrintChunksPlugin;
Loading

0 comments on commit 2bb1035

Please sign in to comment.