TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/meteor/meteor/llms.txt
Use this file to discover all available pages before exploring further.
minifier-js package provides JavaScript minification capabilities for Meteor applications using the Terser minifier. It’s automatically used during production builds to reduce bundle sizes.
Overview
This package exports themeteorJsMinify function that minifies JavaScript code asynchronously using Terser 5.31.0. It’s designed to work seamlessly with Meteor’s build system and includes smart defaults for optimal production code.
Dependencies
Installation
The package is included by default in Meteor’s standard build chain. For manual use:API
meteorJsMinify(source)
Minifies JavaScript source code using Terser. Parameters:source(string): JavaScript code to minify
code(string): Minified JavaScript codeminifier(string): Always returns'terser'
Configuration
The minifier uses the following Terser options:Compression Options
drop_debugger: false- Keeps
debugger;statements in production - Allows debugging in production when needed
- Can be useful for troubleshooting live issues
- Preserves unreferenced functions and variables
- Prevents issues with dynamic code access
- Safer for Meteor’s dynamic loading patterns
- Removes unreachable code paths
- Eliminates code after
return,throw,break, orcontinue - Reduces bundle size without breaking functionality
- Disables typeof optimization
- Fixes known issues in Internet Explorer 10
- See: UglifyJS Issue #1753
- Defines
process.env.NODE_ENVat compile time - Enables dead code elimination for environment checks
- Example:
Safari 10 Fix
safari10: true- Works around the Safari 10/11 async/await bug
- Prevents runtime errors with async functions
- See: Terser Issue #117
NODE_ENV Handling
The minifier respects theNODE_ENV environment variable:
Integration
Build Plugin
The minifier is used by Meteor’s build system during production builds:Custom Minification
For custom build processes:Performance
The minifier is:- Asynchronous: Uses async/await for non-blocking minification
- Lazy-loaded: Terser is loaded on first use to improve startup time
- Compatible: Works with Meteor’s caching system
Backwards Compatibility
The package maintains backwards compatibility:result.code- Always contains minified coderesult.minifier- Always set to'terser'
Best Practices
Environment-Specific Code
Use environment checks for code splitting:Preserve Important Code
Avoid patterns that might be incorrectly removed:Debugging Production
Sincedrop_debugger: false, you can use debugger statements:
Testing
The package includes comprehensive tests:Common Issues
Issue: Code breaks after minification
Solution: Check for:- Missing semicolons
- Reserved keyword usage
- Eval or Function constructor usage
- Dynamic property access
Issue: Larger bundle than expected
Solution: Verify:unused: falseprevents removal of seemingly unused code- Environment-specific code is properly wrapped in
process.env.NODE_ENVchecks - No circular dependencies preventing tree-shaking
Issue: Safari compatibility issues
Solution:- The
safari10: trueoption is already enabled - Ensure you’re using supported async/await patterns
- Test in Safari 10/11 if targeting those versions
Alternatives
For different minification strategies:Version History
- 3.1.0 - Current version using Terser 5.31.0
- Uses Terser instead of legacy UglifyJS
- Async-first API
- Safari 10/11 compatibility built-in