Skip to content

Instantly share code, notes, and snippets.

@lmiller1990
Created September 19, 2025 11:16
Show Gist options
  • Save lmiller1990/e50f932516d4cf812a992749ee667c38 to your computer and use it in GitHub Desktop.
Save lmiller1990/e50f932516d4cf812a992749ee667c38 to your computer and use it in GitHub Desktop.
Dead code elimination
npm install
npx rollup -c rollup.config.js

Output is

{
  console.log('someCode ran');
}
const foo = import.meta.env.VITE_ENV === 'staging';
if (foo) {
console.log('someCode ran');
} else {
console.log('otherCode ran');
}
{
"devDependencies": {
"@rollup/plugin-terser": "^0.4.4",
"rollup": "^4.51.0"
}
}
import replace from '@rollup/plugin-replace';
export default {
input: 'index.js',
output: {
file: 'bundle.js',
format: 'es'
},
plugins: [
// Simulate Vite's env injection
replace({
preventAssignment: true,
'import.meta.env.VITE_ENV': JSON.stringify('staging')
}),
]
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment