Skip to content

Commit

Permalink
getting total bundle size
Browse files Browse the repository at this point in the history
  • Loading branch information
pajaydev committed Jul 15, 2018
1 parent 90034e8 commit 98458de
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Usage
## install

```
npm install --save-dev lasso-unpack
npm install -g lasso-unpack
lasso-unpack <bundle file path>
````
Expand All @@ -23,7 +23,7 @@ parseBundle('lib/build.js');
## Output
Output a `lasso-stats.json` file to the parent directory.
Output a `lasso-stats.json` file to the parent directory, you can check all the files and their sizes bundled by Lasso.
The lasso-stats.json will look like this :
Expand All @@ -43,9 +43,13 @@ The lasso-stats.json will look like this :
input and output example files provided here
https://github.com/ajay2507/lasso-unpack/tree/master/examples

## Issues
If you are facing any issues or have any improvements, you can create issue here
https://github.com/ajay2507/lasso-unpack/issues

## Problem

Developer should know what presents inside bundle created by Lasso. It should not be a black box. lasso-unpack solves this problem, it unpacks the bundle and shows all the files present in the bundle. It includes content and size of js file.
Developer should know what presents inside bundle created by Lasso. It should not be a black box. lasso-unpack solves this problem, it unpacks the bundle and shows all the files present in the bundle. It includes content and size of js. file.

License
========
Expand Down
17 changes: 14 additions & 3 deletions lib/lasso-unpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ const isValidFunctionExpression = require('./utils').isValidFunctionExpression;
const isFunctionExpression = require('./utils').isFunctionExpression;

function parseLassoBundle(fileName) {
console.log("Input path provided => " + path.resolve(fileName));
const fileContent = fs.readFileSync(path.resolve(fileName), 'utf8');
const ast = acorn.parse(fileContent, {
sourceType: 'script'
});

let initial = new Stats();
const walkState = [];
if (ast.body.length === 0) return "Empty File"
if (ast.body.length === 0) return "Empty File";
// get total bundle size.
isProgram(ast, walkState, initial);
// iterate the AST tree.
walk.recursive(
ast,
walkState,
Expand Down Expand Up @@ -76,6 +78,15 @@ function extractLiterals(stats, args) {
}
}

function isProgram(ast, walkState, initial) {
if (ast.type === "Program") {
initial.setPackageName('BundleSize');
initial.setFileName('program');
initial.setSize(ast.end - ast.start);
walkState.push(initial);
}
}

function extractContent(fileContent, stats, node) {
if (isValidFunctionExpression(node)) {
let body = node.body;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lasso-unpack",
"version": "1.0.0",
"version": "1.0.1",
"description": "unpack bundle - Generate stats json from lasso bundle",
"main": "lib/lasso-unpack.js",
"bin": {
Expand Down

0 comments on commit 98458de

Please sign in to comment.