Skip to content
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

feat: log compile stats #503

Merged
merged 12 commits into from
Nov 22, 2022
7 changes: 7 additions & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,13 @@ A [picomatch pattern](https://github.com/micromatch/picomatch), or array of patt

Force Vite to pre-bundle Svelte libraries. Setting this `true` should improve initial page load performance, especially when using large Svelte libraries. See the [FAQ](./faq.md#what-is-going-on-with-vite-and-pre-bundling-dependencies) for details of the pre-bundling implementation.

### disableCompileStats

- **Type** `boolean | 'dev' | 'build'`
- **Default:** `false`

disable svelte compile statistics
dominikg marked this conversation as resolved.
Show resolved Hide resolved

## Experimental options

These options are considered experimental and breaking changes to them can occur in any release! Specify them under the `experimental` option.
Expand Down
18 changes: 14 additions & 4 deletions packages/vite-plugin-svelte/src/utils/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const allowedPluginOptions = new Set([
'ignorePluginPreprocessors',
'disableDependencyReinclusion',
'prebundleSvelteLibraries',
'disableCompileStats',
'experimental'
]);

Expand Down Expand Up @@ -204,12 +205,14 @@ export function resolveOptions(
addExtraPreprocessors(merged, viteConfig);
enforceOptionsForHmr(merged);
enforceOptionsForProduction(merged);
// add after merge, would mangle class functions otherwise
// only add if loglevel is info
if ([undefined, 'info'].includes(viteConfig.logLevel)) {
// mergeConfigs would mangle functions on the stats class, so do this afterwards
const isLogLevelInfo = [undefined, 'info'].includes(viteConfig.logLevel);
const statsDisabledInConfig =
merged.disableCompileStats !== true &&
merged.disableCompileStats !== (merged.isBuild ? 'build' : 'dev');
if (!statsDisabledInConfig && isLogLevelInfo) {
merged.stats = new VitePluginSvelteStats();
}

return merged;
}

Expand Down Expand Up @@ -564,6 +567,13 @@ export interface PluginOptions {
*/
prebundleSvelteLibraries?: boolean;

/**
* disable svelte compile statistics
*
* @default false
*/
disableCompileStats?: 'dev' | 'build' | boolean;

/**
* These options are considered experimental and breaking changes to them can occur in any release
*/
Expand Down