rollup-plugin-optimize-js

raw JSON →
0.0.4 verified Mon Apr 27 auth: no javascript deprecated

Rollup plugin to run minified bundles through the optimize-js tool, which wraps immediately-invoked or likely-to-be-invoked functions in parentheses to improve initial parsing and execution speed. Current version is 0.0.4, last published in 2017 and appears to be unmaintained (no recent updates, repository archived or inactive). Differentiator: it applies optimize-js after minification to restore optimizations that might have been undone by UglifyJS. Consider using modern alternatives like Rollup's built-in optimization or other plugins.

error Error: Could not resolve 'rollup-plugin-optimize-js'
cause Package not installed or not in node_modules.
fix
Run 'npm install rollup-plugin-optimize-js --save-dev' and ensure it's in your dependencies.
error TypeError: optimizeJs is not a function
cause Importing incorrectly, e.g., using default import on CJS that expects named export.
fix
Use 'const optimizeJs = require('rollup-plugin-optimize-js');' in CommonJS, or 'import optimizeJs from 'rollup-plugin-optimize-js';' in ES6.
error Error: The transformBundle hook used by plugin optimize-js is deprecated
cause Using Rollup 1.x+ where transformBundle was removed.
fix
Downgrade Rollup to 0.x or use a different plugin that supports Rollup 1.x+.
deprecated Package is unmaintained since 2017. No support for modern Rollup versions (Rollup > 1.x).
fix Consider using Rollup's built-in optimizations or manually applying optimize-js as a post-build step.
breaking Plugin may cause errors with Rollup 1.x due to API changes (e.g., transformBundle removed).
fix Downgrade Rollup to 0.x or switch to an alternative plugin.
gotcha Must be placed after minification plugins (e.g., uglify) in the plugin list, otherwise it may not work correctly.
fix Ensure order: other plugins -> minify -> optimizeJs.
gotcha Uglify's 'negate_iife' compress option should be false to avoid conflicting with optimize-js's work.
fix Set uglify compress option 'negate_iife: false'.
npm install rollup-plugin-optimize-js
yarn add rollup-plugin-optimize-js
pnpm add rollup-plugin-optimize-js

Shows how to integrate the plugin in a Rollup config, applying it after uglify to optimize invoked functions.

// rollup.config.js
import optimizeJs from 'rollup-plugin-optimize-js';
import { uglify } from 'rollup-plugin-uglify';
import buble from 'rollup-plugin-buble';

export default {
  input: 'src/index.js',
  output: {
    file: 'bundle.js',
    format: 'iife',
    sourcemap: true
  },
  plugins: [
    buble(),
    uglify({
      compress: {
        negate_iife: false // avoid conflict with optimize-js
      }
    }),
    optimizeJs()
  ]
};