简体   繁体   English

通过dart2js进行飞镖包管理

[英]Dart Package Management via dart2js

I'm learning Dart and its dependency manager pub and am having a tough time seeing the "forest through the trees" here. 我正在学习Dart及其依赖经理pub ,我很难看到这里的“穿越树林”。

Say I want to use Polymer.dart in my project. 假设我想在我的项目中使用Polymer.dart So, in my project root, I create the following pubspec.yaml : 所以,在我的项目根目录中,我创建了以下pubspec.yaml

name: test_dart
description: A sample web application
dependencies:
    browser: any
    polymer: ">=0.9.0 <0.10.0"

I then run pub get , which goes to the pub repo and fetches the browser and polymer dependencies that I've specified. 然后我运行pub get ,它进入pub repo并获取我指定的browserpolymer依赖项。 It then creates a packages directory in my project root, which now means I have a project that looks like: 然后它在我的项目根目录中创建一个packages目录,这意味着我有一个看起来像这样的项目:

MyDartProject/
    pubspec.yaml
    myapp.dart
    packages/
        browser/
            ...
        ...all the packages that ship with Polymer

Now I start coding my Dart web app ( myapp.dart ), which will references various Polymer and browser types/functions/etc. 现在我开始编写我的Dart Web应用程序( myapp.dart ),它将引用各种Polymer和browser类型/函数/等。 in its source code. 在其源代码中。

When I'm all done, I want to create a JavaScript file called myapp.js . 当我完成后,我想创建一个名为myapp.js的JavaScript文件。

According to the dart2js docs , I need to run something like: 根据dart2js文档 ,我需要运行如下:

dart2js --out=myapp.js --package-root=??? myapp.dart

How do I include all the browser & polymer packages on the buildpath? 如何在构建路径中包含所有浏览器和聚合物包?

There is a "pub build" option now. 现在有一个“pub build”选项。

http://pub.dartlang.org/doc/pub-build.html http://pub.dartlang.org/doc/pub-build.html

Use pub build when you're ready to deploy your web app. 准备好部署Web应用程序时使用pub build。 When you run pub build, it generates the assets for the current package and all of its dependencies, putting them into a new directory named build. 当您运行pub build时,它会为当前包及其所有依赖项生成资产,并将它们放入名为build的新目录中。

$ cd ~/dart/helloworld
$ pub build
Building helloworld......
Built 5 files!

If the build directory already exists, pub build deletes it and then creates it again. 如果构建目录已存在,pub构建将删除它,然后再次创建它。

That should do everything you are after here. 这应该是你在这里做的一切。 You can also launch it from the IDE by right clicking on the pubspec.yaml file and choose "pub build" 您也可以通过右键单击pubspec.yaml文件从IDE启动它并选择“pub build”

EDIT: You should also see the links in zoechi's answer. 编辑:您还应该看到zoechi的答案中的链接。

If you run dart2js from your MyDartProject directory you don't have to provide --package-root parameter. 如果从MyDartProject目录运行dart2js,则不必提供--package-root参数。

An alternative way is running pub build . 另一种方法是运行pub build If you use Polymer you need to add a transformers section. 如果使用Polymer,则需要添加transformers部分。

see also 也可以看看

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM