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

build.chunkSizeLimit #18496

Open
4 tasks done
mfulton26 opened this issue Oct 28, 2024 · 2 comments
Open
4 tasks done

build.chunkSizeLimit #18496

mfulton26 opened this issue Oct 28, 2024 · 2 comments

Comments

@mfulton26
Copy link

Description

I appreciate the warning from build.chunkSizeWarningLimit but I want to fail my build in CI if the limit is exceeded… in fact, I might want to fail the build in CI if vite prints any warnings but at a minimum for this one.

Suggested solution

Have a flag to fail on warnings, a flag to fail on chunk size warning limit exceeded, or a separate build option to set a threshold/error limit on chunk size.

I think this flag could be enabled automatically whenever the CI env var is set but that might start to fail builds unexpectedly so an opt-in approach may be best for now.

Alternative

Use separate solutions like bundlesize.

Additional context

#16050

Validations

@sapphi-red
Copy link
Member

sapphi-red commented Oct 29, 2024

As a workaround, you can use customLogger option to achieve this:

import { createLogger, defineConfig } from 'vite';

const logger = createLogger('warn');
const loggerWarn = logger.warn;
logger.warn = (msg, options) => {
  if (msg.includes('Some chunks are larger than')) {
    throw new Error(msg);
  }
  loggerWarn(msg, options);
};

export default defineConfig({
  build: {
    chunkSizeWarningLimit: 1,
  },
  customLogger: logger,
});

https://stackblitz.com/edit/vitejs-vite-6cfnvs?file=vite.config.ts&terminal=build

@mfulton26
Copy link
Author

Thank you @sapphi-red, that looks very promising. I'll try it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants