Skip to content

Commit 7a8b626

Browse files
feat: support gzip option
1 parent 6b27d0d commit 7a8b626

File tree

4 files changed

+11
-14
lines changed

4 files changed

+11
-14
lines changed

README.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,12 @@ Now whenever you want to analyze your angular project just run a command `ng run
2929

3030
## 📦 Options <a name="options"></a>
3131

32-
#### --configuration <a name="configuration"></a>
3332

34-
#### --no-build <a name="no-build"></a>
33+
#### --gzip <a name="gzip"></a>
3534
- **optional**
36-
- Default: `false` (string)
35+
- Default: `false` (boolean)
3736
- Example:
38-
- `ng run [YOUR_PROJECT_NAME]:analyze --no-build` – Angular project is NOT built
39-
40-
Skip build process during analysis.
41-
This can be used when you are sure that you haven't changed anything and want to analyze the bundle
37+
- `ng run [YOUR_PROJECT_NAME]:analyze --gzip` – Give the stats of gzip bundle.
4238

4339
# License
4440
[MIT](https://github.com/ngx-builders/source-map-analyzer/blob/master/LICENSE)

analyze/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,20 @@ import { json } from '@angular-devkit/core';
33
import { Schema } from './schema';
44
import util from 'util';
55
import { exec } from 'child_process';
6-
import fs from 'fs';
7-
import inquirer from 'inquirer';
86

97
export const execAsync = util.promisify(exec);
108

119
export default createBuilder<any>(
1210
async (builderConfig: Schema, context: BuilderContext): Promise<BuilderOutput> => {
1311
try {
14-
context.reportStatus(`Executing "${builderConfig.noBuild}"...`);
12+
context.reportStatus(`Starting Build`);
1513
// const child = childProcess.spawn(options.command, options.args, { stdio: 'pipe' });
1614

1715
const configuration = 'production';
1816

1917
const overrides = {
2018
// this is an example how to override the workspace set of options
21-
...({ sourceMap: true })
19+
...({ sourceMap: true, budgets: [] })
2220
};
2321

2422
const build = await context.scheduleTarget({
@@ -31,7 +29,10 @@ export default createBuilder<any>(
3129

3230
if (result.success) {
3331
const mainFile = '*es2015.*.js';
34-
const explorerCommand = `npx source-map-explorer ${builderConfig.outputPath}/${mainFile}`;
32+
let explorerCommand = `npx source-map-explorer ${builderConfig.outputPath}/${mainFile}`;
33+
if (builderConfig.gzip) {
34+
explorerCommand = `${explorerCommand} --gzip`;
35+
}
3536
const { stdout, stderr } = await execAsync(explorerCommand);
3637
context.logger.info(stdout);
3738
context.logger.info(stderr);

analyze/schema.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export interface Schema {
2-
noBuild?: boolean;
32
outputPath: string;
3+
gzip?: boolean;
44
}

analyze/schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"$schema": "http://json-schema.org/schema",
33
"type": "object",
44
"properties": {
5-
"noBuild": {
5+
"gzip": {
66
"type": "boolean"
77
},
88
"outputPath": {

0 commit comments

Comments
 (0)