8000 Feat/webpack profile by rigor789 · Pull Request #9804 · NativeScript/NativeScript · GitHub
[go: up one dir, main page]

Skip to content

Feat/webpack profile #9804

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/webpack5/__tests__/configuration/base.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,14 @@ describe('base configuration', () => {
force: true,
});
});

it('supports --env.profile', () => {
init({
platform: 'ios',
profile: true,
});
const config = base(new Config());

expect(config.get('profile')).toBe(true);
});
});
24 changes: 23 additions & 1 deletion packages/webpack5/src/bin/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node

import { redBright, green, greenBright } from 'chalk';
import { redBright, green, greenBright, yellow } from 'chalk';
import { program } from 'commander';
import dedent from 'ts-dedent';
import webpack from 'webpack';
Expand Down Expand Up @@ -115,6 +115,28 @@ program
errorDetails: env.verbose,
})
);

// if webpack profile is enabled we write the stats to a JSON file
if (configuration.profile || env.profile) {
console.log(
[
'',
'|',
`| The build profile has been written to ${yellow(
'webpack.stats.json'
)}`,
`| You can analyse the stats at ${green(
'https://webpack.github.io/analyse/'
)}`,
'|',
'',
].join('\n')
);
fs.writeFileSync(
path.join(process.cwd(), 'webpack.stats.json'),
JSON.stringify(stats.toJson())
);
}
}
};

Expand Down
5 changes: 5 additions & 0 deletions packages/webpack5/src/configuration/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
});
});

// enable profiling with --env.profile
config.when(env.profile, (config) => {
config.profile(true);
});

// worker-loader should be declared before ts-loader
config.module
.rule('workers')
Expand Down
3 changes: 3 additions & 0 deletions packages/webpack5/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ export interface IWebpackEnv {
// enable verbose output
verbose?: boolean;

// enable webpack profiling
profile?: boolean;

// misc
replace?: string[] | string;
}
Expand Down
0