You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
rollup-plugin-consts let you use constants that are replaced at build time, such
as inlining your NODE_ENV. Unlike similar plugins such as
rollup-plugin-replace,
rollup-plugin-consts doesn't magically replace strings in your script. Instead,
you import them like a module.
// script.jsimportenvironmentfrom'consts:environment';if(environment==='production'){// Production only code ...}else{// Development only code ...}
All consts modules have the prefix consts: followed by the name of the
constant, such as environment or testing. Rollup can reduce simple if
statements like the one above.
// script.min.js// environment == 'production'{// Production only code ...}
Generally, you need to ensure that rollup-plugin-consts goes before other
things (like rollup-plugin-commonjs) in your plugins array, so that those
plugins can apply any optimisations such as dead code removal.
{// All options are treated as `string: replacement` replacers...testing: false,version: '1.0.0',environment: 'development',// Objects can be used as replacements too!config: {names: ['foo','bar']},}
TypeScript
The consts function is has a typings file. See
Usage with TypeScript
to check how to create additional typings files for importing constants.