schultek / jaspr

Modern web framework for building websites in Dart. Supports SPAs and SSR.
https://jasprpad.schultek.de
MIT License
996 stars 59 forks source link

Closes #193 Add optimization options to jaspr build command #196

Closed walsha2 closed 3 months ago

walsha2 commented 3 months ago

Description

See #193 For details and rationale.

The implementation here inherits form the dart2js optimization options:

>>> dart compile js -h

Usage: dart compile js [arguments] <dart entry point>
  -h, --help      Print this usage information.
  -h -v           Show detailed information about all options.
  -o, --output    Write the output to <file name>.
  -O<0,1,2,3,4>   Set the compiler optimization level (defaults to -O1).
     -O0          No optimizations (only meant for debugging the compiler).
     -O1          Default (includes whole program analyses and inlining).
     -O2          Safe production-oriented optimizations (like minification).
     -O3          Potentially unsafe optimizations (see -h -v for details).
     -O4          More agressive unsafe optimizations (see -h -v for details).

The new, analogous, jaspr build command options:

>>> jaspr build -h

-O, --optimize               Set the dart2js compiler optimization level

          [0]                No optimizations (only meant for debugging the compiler).
          [1]                Includes whole program analyses and inlining.
          [2] (default)      Safe production-oriented optimizations (like minification).
          [3]                Potentially unsafe optimizations.
          [4]                More aggressive unsafe optimizations.

Note that dart compile js uses O1 as the default. Since jaspr build is intended for release/production, it seems that a better default here would be O2.

Users can change the optimization level via this command option. To revert to the previous build configuration, simply specify:

jaspr build --optimize 1
jaspr build  -O 1

Results

New results using this updated jaspr build (without any options specified).

du -sh build/jaspr/web/*.js && du -sh build/jaspr/web/components/*.js

Before

1.0M    build/jaspr/web/main.clients.dart.js
560K    build/jaspr/web/main.clients.dart.js_1.part.js
1.5M    build/jaspr/web/components/app.client.dart.js

After

360K    build/jaspr/web/main.clients.dart.js
180K    build/jaspr/web/main.clients.dart.js_1.part.js
528K    build/jaspr/web/components/app.client.dart.js

Type of Change

Ready Checklist

github-actions[bot] commented 3 months ago

Package Version Report

The following packages have been updated: jaspr : 0.10.0 -> 0.11.0 jaspr_builder : 0.10.0 -> 0.11.0 jaspr_cli : 0.10.0 -> 0.11.0 jaspr_flutter_embed : 0.2.0 -> 0.3.0 jaspr_riverpod : 0.3.9 -> 0.3.10 jaspr_router : 0.3.1 -> 0.3.2 jaspr_test : 0.10.0 -> 0.11.0

codecov[bot] commented 3 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 60.83%. Comparing base (6ab1cdb) to head (cd028e9). Report is 1 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #196 +/- ## ========================================== + Coverage 59.94% 60.83% +0.89% ========================================== Files 101 117 +16 Lines 4219 5079 +860 ========================================== + Hits 2529 3090 +561 - Misses 1690 1989 +299 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

schultek commented 3 months ago

LGTM