'production' | 'development' | 'none'>= 1.0.0Sets the Rsbuild build mode. Each mode applies different defaults and optimizations; for example, production minifies code by default.
The Rsbuild mode value is also passed to Rspack's mode configuration.
The mode value does not change which .env file loads because .env files resolve before the Rsbuild config file.
Use the --env-mode option in the Rsbuild CLI to specify the env mode. See "Env mode" for details.
The default value of mode depends on the process.env.NODE_ENV environment variable:
NODE_ENV is production, the default value is production.NODE_ENV is development, the default value is development.NODE_ENV has any other value, the default value is none.If you set mode, the NODE_ENV value will be ignored.
export default {
mode: 'production',
};When using the Rsbuild CLI:
rsbuild dev will set the default values of NODE_ENV and mode to development.rsbuild build and rsbuild preview will set the default values of NODE_ENV and mode to production.When using the Rsbuild JavaScript API:
NODE_ENV and mode to development.NODE_ENV and mode to production.If mode is development:
process.env.NODE_ENV in the source code will be replaced with 'development'.import.meta.env.MODE in the source code will be replaced with 'development'.import.meta.env.DEV in the source code will be replaced with true.import.meta.env.PROD in the source code will be replaced with false.If mode is production:
process.env.NODE_ENV in the source code will be replaced with 'production'.import.meta.env.MODE in the source code will be replaced with 'production'.import.meta.env.DEV in the source code will be replaced with false.import.meta.env.PROD in the source code will be replaced with true.If mode is none:
process.env.NODE_ENV in the source code will not be replaced.import.meta.env.MODE in the source code will be replaced with 'none'.import.meta.env.DEV in the source code will be replaced with false.import.meta.env.PROD in the source code will be replaced with false.