10000 feat: support webpack profiling (#9804) · NativeScript/NativeScript@af4b7e3 · GitHub
[go: up one dir, main page]

Skip to content

Commit af4b7e3

Browse files
feat: support webpack profiling (#9804)
Co-authored-by: Martin Guillon <martin.guillon@akylas.fr>
1 parent 151d6e8 commit af4b7e3

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

packages/webpack5/__tests__/configuration/base.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,14 @@ describe('base configuration', () => {
109109
force: true,
110110
});
111111
});
112+
113+
it('supports --env.profile', () => {
114+
init({
115+
platform: 'ios',
116+
profile: true,
117+
});
118+
const config = base(new Config());
119+
120+
expect(config.get('profile')).toBe(true);
121+
});
112122
});

packages/webpack5/src/bin/index.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env node
22

3-
import { redBright, green, greenBright } from 'chalk';
3+
import { redBright, green, greenBright, yellow } from 'chalk';
44
import { program } from 'commander';
55
import dedent from 'ts-dedent';
66
import webpack from 'webpack';
@@ -115,6 +115,28 @@ program
115115
errorDetails: env.verbose,
116116
})
117117
);
118+
119+
// if webpack profile is enabled we write the stats to a JSON file
120+
if (configuration.profile || env.profile) {
121+
console.log(
122+
[
123+
'',
124+
'|',
125+
`| The build profile has been written to ${yellow(
126+
'webpack.stats.json'
127+
)}`,
128+
`| You can analyse the stats at ${green(
129+
'https://webpack.github.io/analyse/'
130+
)}`,
131+
'|',
132+
'',
133+
].join('\n')
134+
);
135+
fs.writeFileSync(
136+
path.join(process.cwd(), 'webpack.stats.json'),
137+
JSON.stringify(stats.toJson())
138+
);
139+
}
118140
}
119141
};
120142

packages/webpack5/src/configuration/base.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,11 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
222222
});
223223
});
224224

225+
// enable profiling with --env.profile
226+
config.when(env.profile, (config) => {
227+
config.profile(true);
228+
});
229+
225230
// worker-loader should be declared before ts-loader
226231
config.module
227232
.rule('workers')

packages/webpack5/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ export interface IWebpackEnv {
4343
// enable verbose output
4444
verbose?: boolean;
4545

46+
// enable webpack profiling
47+
profile?: boolean;
48+
4649
// misc
4750
replace?: string[] | string;
4851
watchNodeModules?: boolean;

0 commit comments

Comments
 (0)
0