如何缩小从Dart编辑器编译的JavaScript代码? [英] How do I minify JavaScript code compiled from Dart Editor?
问题描述
我使用Dart编辑器来构建一个Dart应用程序。我编译为JavaScript在所有浏览器上运行。我想缩小输出JavaScript。
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 the command line?
我知道在命令行上,我可以使用 dart2js --minify app。 dart
。
I know that on the command line, I can use dart2js --minify app.dart
. How do I make this automatic from Dart Editor?
推荐答案
有两种快速简单的方法来缩小你编写的Javascript代码
通过Dart编辑器。推荐的方法是使一个小的除了
你的pubspec.yaml文件。
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.
以下是一个示例:
Name: my-app
description: An Angular web application
dependencies:
angular: any
browser: any
transformers:
- angular
添加此附加选项即可:
Name: my-app
description: An Angular web application
dependencies:
angular: any
browser: any
transformers:
- angular
- $dart2js:
{'minify':true}
第二种方法是更改
应用程序的启动选项,并取消选择VM设置模式
。在
中的换句话:运行>托管启动>点击应用启动文件> VM设置>取消选中以检查模式运行
。
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".
资料来源: https: //www.dartlang.org/tools/pub/dart2js-transformer.html
PS:重要的是您设置 $ dart2js
字段,或者
无法正确构建。这是目前的错误或文档问题。
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.
这篇关于如何缩小从Dart编辑器编译的JavaScript代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!