{"id":12891,"library":"bit-bundler-minifyjs","title":"bit-bundler JavaScript Minifier Plugin","description":"bit-bundler-minifyjs is a specialized plugin designed to integrate JavaScript minification capabilities into the bit-bundler ecosystem. It acts as a lightweight wrapper around the UglifyJS library, leveraging its robust optimization and minification features. The current stable version is 3.1.0. While no explicit release cadence is stated, the package has seen recent maintenance releases (e.g., v3.0.4), indicating ongoing support for critical fixes. Its primary differentiator is its seamless integration with bit-bundler, allowing developers to configure minification options per bundle, which is particularly useful in code-splitting scenarios. It also provides convenience options like `banner` and `sourceMap` that abstract UglifyJS's underlying configuration, streamlining its usage within the bit-bundler build process.","status":"active","version":"3.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/MiguelCastillo/bit-bundler-minifyjs","tags":["javascript","bit-bundler","bit-bundler-plugin"],"install":[{"cmd":"npm install bit-bundler-minifyjs","lang":"bash","label":"npm"},{"cmd":"yarn add bit-bundler-minifyjs","lang":"bash","label":"yarn"},{"cmd":"pnpm add bit-bundler-minifyjs","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"This package is a plugin for bit-bundler and requires it for core functionality.","package":"bit-bundler","optional":false},{"reason":"It's a wrapper for UglifyJS, which performs the actual JavaScript minification.","package":"uglify-js","optional":false}],"imports":[{"note":"When used within the `bit-bundler` configuration array, the plugin is referenced by its package name string. `bit-bundler` internally resolves and loads it using CommonJS `require`.","wrong":"import MinifyJS from 'bit-bundler-minifyjs';","symbol":"bit-bundler-minifyjs (string)","correct":"var bitbundler = new Bitbundler({\n  bundler: [\n    \"bit-bundler-minifyjs\"\n  ]\n});"},{"note":"When needing to pass options directly to the plugin, `require` the module, which exports a function that accepts an options object and returns the plugin instance.","wrong":"const minifyjs = new (require('bit-bundler-minifyjs'))();","symbol":"minifyjs (function)","correct":"const minifyjs = require('bit-bundler-minifyjs');\n// ... then use in bundler config:\n// bundler: [minifyjs({ banner: '/*! My App */' })]"},{"note":"For per-bundle configuration with `bit-bundler-splitter`, options for `bit-bundler-minifyjs` are nested under a key matching the split bundle's name (e.g., 'vendor').","symbol":"minifyjs (with code splitting)","correct":"Bitbundler.bundle({ /* ... */ }, {\n  bundler: [\n    [\"bit-bundler-splitter\", { /* ... */ }],\n    [\"bit-bundler-minifyjs\", {\n      vendor: { sourceMap: false }\n    }]\n  ]\n});"}],"quickstart":{"code":"const Bitbundler = require(\"bit-bundler\");\nconst path = require(\"path\");\nconst fs = require(\"fs\");\n\n// Create a dummy input file for a runnable example\nconst inJsContent = `\nconsole.log(\"Hello from in.js\");\nfunction calculateSquare(num) {\n  return num * num;\n}\nconsole.log(calculateSquare(7));\n`;\nconst inJsPath = path.join(__dirname, \"in.js\");\nfs.writeFileSync(inJsPath, inJsContent);\n\nconst outJsPath = path.join(__dirname, \"out.js\");\n// Clean up previous run's output if it exists\nif (fs.existsSync(outJsPath)) {\n  fs.unlinkSync(outJsPath);\n}\n\n// Configure bit-bundler with the minifyjs plugin\nconst bitbundler = new Bitbundler({\n  bundler: [\n    \"bit-bundler-minifyjs\" // The plugin is added here\n  ]\n});\n\n// Bundle and minify the JavaScript file\nbitbundler.bundle({\n  src: inJsPath,\n  dest: outJsPath\n}).then(() => {\n  console.log(`Successfully bundled and minified to: ${outJsPath}`);\n  // Optional: Read a sample of the output to confirm minification\n  const minifiedContent = fs.readFileSync(outJsPath, 'utf8');\n  console.log(\"Minified content sample (first 100 chars):\");\n  console.log(minifiedContent.substring(0, 100) + \"...\");\n}).catch(err => {\n  console.error(\"Bundling failed:\", err);\n}).finally(() => {\n  // Clean up dummy input and output files\n  if (fs.existsSync(inJsPath)) fs.unlinkSync(inJsPath);\n  if (fs.existsSync(outJsPath)) fs.unlinkSync(outJsPath);\n});","lang":"javascript","description":"This quickstart demonstrates how to integrate `bit-bundler-minifyjs` into a basic `bit-bundler` setup to minify a JavaScript file."},"warnings":[{"fix":"Do not rely on `bundle.dest` for directly providing file maps to UglifyJS via this plugin. Ensure you are on a version of `bit-bundler` that handles this internally, or adjust your build process to explicitly manage file maps if necessary.","message":"The way `bundle.dest` was used to feed a map of files to UglifyJS was removed in v3.0.4 because `bundle.dest` is not always a file path string and could cause crashes. This functionality was moved to be handled internally within `bit-bundler` itself.","severity":"breaking","affected_versions":">=3.0.4"},{"fix":"When configuring, check the plugin's README for its specific options (e.g., `banner`, `sourceMap`) before directly referencing UglifyJS options. Understand how the plugin's options map to UglifyJS's underlying configuration.","message":"Options for `bit-bundler-minifyjs` are directly forwarded to UglifyJS, but some options like `banner` and `sourceMap` are specific to the plugin and override or map to UglifyJS options (`output.preamble`).","severity":"gotcha","affected_versions":">=1.0"},{"fix":"To extract sourcemaps, install and configure `bit-bundler-extractsm` alongside `bit-bundler-minifyjs` in your `bit-bundler` setup.","message":"Sourcemaps are generated inline by default. If you need to split them into a separate file, you will need to use an additional plugin like `bit-bundler-extractsm`.","severity":"gotcha","affected_versions":">=1.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":""}