{"id":25204,"library":"elm-optimize-level-2","title":"elm-optimize-level-2","description":"A CLI tool (v0.3.5) that applies a second level of optimization to the JavaScript output of the Elm compiler, producing faster code while maintaining Elm semantics. It can be used as a drop-in replacement for `elm make --optimize` and supports an `--optimize-speed` flag for even faster code at the cost of ~5% larger bundle size. The project is experimental and may introduce breaking changes. Key differentiators: Elm-specific JS transformations (e.g., tweaking record updates), active development with community benchmarks, and no built-in minification.","status":"active","version":"0.3.5","language":"javascript","source_language":"en","source_url":"https://github.com/mdgriffith/elm-optimize-level-2","tags":["javascript","typescript"],"install":[{"cmd":"npm install elm-optimize-level-2","lang":"bash","label":"npm"},{"cmd":"yarn add elm-optimize-level-2","lang":"bash","label":"yarn"},{"cmd":"pnpm add elm-optimize-level-2","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Requires Elm to be installed globally to compile Elm code","package":"elm","optional":false}],"imports":[{"note":"The package is ESM-only for Node >= 16 and ships TypeScript types. There is no CommonJS module export; using require() will fail.","wrong":"const elmOptimizeLevel2 = require('elm-optimize-level-2')","symbol":"default","correct":"import { elmOptimizeLevel2 } from 'elm-optimize-level-2'"},{"note":"The package is primarily a CLI tool. To use programmatically, import the default export and call it with options.","wrong":"npm run elm-optimize-level-2","symbol":"CLI","correct":"npx elm-optimize-level-2 Main.elm"},{"note":"TypeScript types are bundled; use type import for TypeScript projects.","wrong":"","symbol":"types","correct":"import type { OptimizeOptions } from 'elm-optimize-level-2'"}],"quickstart":{"code":"// Install globally\n// $ npm install -g elm-optimize-level-2\n\n// Then compile an Elm file:\n// $ elm-optimize-level-2 Main.elm --output app.js\n\n// Or with the --optimize-speed flag:\n// $ elm-optimize-level-2 Main.elm --optimize-speed --output app.js\n\n// Programmatic usage:\nimport elmOptimizeLevel2 from 'elm-optimize-level-2';\nimport { promises as fs } from 'fs';\n\nasync function compile() {\n  const result = await elmOptimizeLevel2({\n    entry: 'Main.elm',\n    output: 'app.js',\n    optimizeSpeed: false,\n  });\n  await fs.writeFile('app.js', result.code);\n}\n\ncompile();","lang":"typescript","description":"Shows installation, CLI usage with output filename and --optimize-speed flag, and programmatic compilation using ESM import with TypeScript."},"warnings":[{"fix":"Use a separate tool (e.g., elm-live) or serve the JS file with an HTML host.","message":"elm-optimize-level-2 only generates JS files; it does not support HTML generation like `elm make`.","severity":"breaking","affected_versions":"*"},{"fix":"Do not use `--optimize-speed` if bundle size is a constraint.","message":"The `--optimize-speed` flag may produce ~5% larger bundle sizes. Consider whether asset size or runtime performance is more important.","severity":"deprecated","affected_versions":">=0.1.0"},{"fix":"Only use in production after thorough testing.","message":"This package is experimental and may break your Elm code in unexpected ways. Run your test suite after each compilation.","severity":"gotcha","affected_versions":"*"},{"fix":"Use a minifier like Terser and gzip before deploying.","message":"Does not minify or gzip the output; you must do that separately before deployment.","severity":"gotcha","affected_versions":"*"},{"fix":"Set `\"type\": \"module\"` in your package.json or use `.mjs` extension.","message":"Requires Node.js >= 16 and ES modules; does not support CommonJS.","severity":"breaking","affected_versions":">=0.3.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use `import` or set \"type\": \"module\" in package.json.","cause":"The package is ESM-only and cannot be used with require() in CommonJS contexts.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module"},{"fix":"Install globally: `npm install -g elm-optimize-level-2` or use `npx elm-optimize-level-2`.","cause":"The package is not installed globally or not in PATH.","error":"elm-optimize-level-2: command not found"},{"fix":"Check documentation or README; run without arguments to see usage (if supported).","cause":"The CLI does not support --help; try --help?","error":"elm-optimize-level-2: error: unrecognized argument: --help"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}