How do I minify JavaScript code compiled from Dart Editor?

前端 未结 2 2101

I am using Dart Editor to build a Dart app. I am compiling to JavaScript to run on all browsers. I want to minify the output JavaScript. How can I do this without dropping to th

2条回答
  •  北海茫月
    2021-02-07 09:15

    There are two quick and easy ways to minify your complied Javascript code through the Dart Editor. The recommended way is make a small addition to your pubspec.yaml file.

    Here's an example:

      Name: my-app 
      description: An Angular web application 
      dependencies: 
        angular: any 
        browser: any 
      transformers: 
      - angular 
    

    Include this additional option and you're done:

     Name: my-app 
      description: An Angular web application
      dependencies:
        angular: any
        browser: any
      transformers:
      - angular
      - $dart2js: 
        {'minify':true}
    

    The second method is to change the launch options of your app and deselect the VM setting Run in checked mode. In order words: Run > Managed Launches > Click on App Launch File > VM settings > Un-check "Run in checked mode".

    I haven't tried this last option yet, but according to the documentation it should auto-minify when run in "production mode".

    Source: https://www.dartlang.org/tools/pub/dart2js-transformer.html

    P.S.: It is important that you set the $dart2js field with a map or it will fail to build properly. This is currently either a bug or documentation issue.

提交回复
热议问题