Skip to content

Add Dart code minifier for utility use (AI prompts, tooling, sharing) #60800

Open
@yalpayelekon

Description

@yalpayelekon

Use Case
In some contexts like AI prompts, developer tools, or code-sharing platforms, a compact version of Dart code would be more appropriate than the standard formatted version. Dart’s formatting is great for readability, but sometimes, a minified format is better for:

  • Fitting code into token-limited AI prompts
  • Sending snippets to a custom interpreter or browser-based tool
  • Sharing short examples in a compressed form

Alternatives considered

  • Manually removing whitespace — slow and error-prone
  • Using production minification — not usable for readable source snippets
  • There is no current tool or pub.dev package that provides a lightweight, syntax-preserving Dart minifier

Proposal
Add an optional Dart code minifier, similar to JavaScript minifiers, as a command-line tool or dart format flag:

dart format --minify lib/example.dart

Features could include:

  • Stripping newlines and extra indentation
  • Optionally shortening variable names (if feasible)
  • Preserving syntax and logic, not intended for production builds

This tool would be very helpful in development workflows, AI integrations, and dev tooling. It should ideally be provided by Dart SDK, not a package, since it relates to the language’s formatting rules and syntax tree.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-toolsA meta category for issues that should be addressed by tooling (prefer more concrete areas).dart-cli-formatIssues related to the 'dart format' tool

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions