JavaScript Minification for Ember CLI

4.0.2 · active · verified Sun Apr 19

ember-cli-terser is an Ember CLI addon designed to integrate the Terser JavaScript minifier into the Ember CLI build pipeline. Its primary function is to automatically minify JavaScript files during production builds, thereby optimizing application size and improving loading performance. The current stable version is 4.0.2. Its release cadence is generally aligned with major versions of the underlying `terser` library and updates to the Ember CLI ecosystem, often involving necessary Node.js support changes. A key differentiator is its seamless integration into the Ember CLI environment, allowing developers to configure `terser` options directly within `ember-cli-build.js` without manual adjustments to the build process. It effectively supersedes older minifiers like UglifyJS, providing modern JavaScript minification capabilities for Ember applications.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to install `ember-cli-terser` and configure its minification options, including Terser-specific settings and source map handling, within an Ember CLI project's `ember-cli-build.js` file.

// Terminal (run in your Ember CLI project root)
ember install ember-cli-terser

// ember-cli-build.js
const EmberApp = require('ember-cli/lib/broccoli/ember-app');
// If using Embroider, you might also have this:
// const { maybeEmbroider } = require('@embroider/test-setup');

module.exports = function(defaults) {
  let app = new EmberApp(defaults, {
    // Configure ember-cli-terser options here
    'ember-cli-terser': {
      enabled: true, // Default: true for production builds, false for development
      exclude: ['vendor.js'], // Example: Exclude specific files from minification
      terser: {
        compress: {
          sequences: 50,
          dead_code: true,
          drop_console: process.env.EMBER_ENV === 'production' // Drop console logs only in production
        },
        output: {
          semicolons: false // Example: Omit semicolons where possible
        },
        mangle: {
          safari10: true // Specific fix for Safari 10 bugs
        }
      },
      // Options for broccoli-terser-sourcemap can also be top-level
      hiddenSourceMap: true // Prevents adding '//# sourceMappingURL' comments
    },
    // General EmberApp sourcemap configuration
    sourcemaps: {
      enabled: process.env.EMBER_ENV === 'production', // Enable sourcemaps only for production builds
      extensions: ['js']
    }
  });

  // If using Embroider:
  // return maybeEmbroider(app);

  return app;
};

view raw JSON →