Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(262)

Side by Side Diff: src/site/docs/pub-package-manager/index.markdown

Issue 10788006: new site (Closed) Base URL: https://code.google.com/p/dartlang-site/@master
Patch Set: final patch Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/site/docs/library-tour/index.markdown ('k') | src/site/docs/sdk/index.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 --- 1 ---
2 layout: default 2 layout: default
3 title: "pub: The Dart Package Manager" 3 title: "pub: The Dart Package Manager"
4 description: "With pub, you can use third-party Dart libraries in 4 description: "With pub, you can use third-party Dart libraries in
5 your web and command-line Dart apps." 5 your web and command-line Dart apps."
6 --- 6 ---
7 7
8 # {{ page.title }} 8 # {{ page.title }}
9 9
10 <aside class="note"> 10 <aside>
11 <b>Note:</b> pub is under active development, so expect 11 <div class="alert alert-info">
12 some changes to the functionality of the tool and these docs. 12 <strong>Note:</strong>
13 Pub is under active development, so expect
14 some changes to the functionality of the tool and these docs.
15 </div>
13 </aside> 16 </aside>
14 17
15 This page tells you how to use the _pub_ tool (`bin/pub`) 18 This page tells you how to use the _pub_ tool (`bin/pub`)
16 to manage Dart packages. A Dart package is simply 19 to manage Dart packages. A Dart package is simply
17 a directory containing any number of Dart libraries and their dependencies. 20 a directory containing any number of Dart libraries and their dependencies.
18 21
19 The `bin/pub` executable is in the [Dart SDK](/docs/sdk/). 22 The `bin/pub` executable is in the [Dart SDK](/docs/sdk/).
20 You can either [download the SDK separately](/docs/sdk/#download) 23 You can either [download the SDK separately](/docs/sdk/#download)
21 or get it as part of the [Dart Editor package](/docs/editor/#download). 24 or get it as part of the [Dart Editor package](/docs/editor/#download).
22 25
23 To use a library that's in a Dart package, 26 To use a library that's in a Dart package,
24 you need to create a **pubspec**, use pub to install the package, 27 you need to create a **pubspec**, use pub to install the package,
25 point Dart to the packages location, and then import the library. 28 point Dart to the packages location, and then import the library.
26 29
27 ## Creating a pubspec 30 ## Creating a pubspec
28 31
29 To use a package, your application must define a pubspec 32 To use a package, your application must define a pubspec
30 that lists dependencies and their download locations. 33 that lists dependencies and their download locations.
31 This file is named **pubspec.yaml** and is placed into the same directory 34 This file is named **pubspec.yaml** and is placed into the
32 as the file containing the app's main() method. 35 root directory of your package or app.
33 36
34 Here is an example of a pubspec.yaml file that associates the 37 Here is an example of a pubspec.yaml file that associates the
35 `awesome` package with a git repository: 38 `awesome` package with a git repository:
36 39
37 {% highlight yaml %} 40 {% highlight yaml %}
38 dependencies: 41 dependencies:
39 awesome: 42 awesome:
40 git: git://github.com/munificent/awesome.git 43 git: git://github.com/munificent/awesome.git
41 {% endhighlight %} 44 {% endhighlight %}
42 45
46 Packages can be installed from git today, and in the future
47 we expect to support other sources such as a hosted
48 service at pub.dartlang.org.
49
43 The pubspec uses the [YAML](http://yaml.org/) format. 50 The pubspec uses the [YAML](http://yaml.org/) format.
44 51
45 ## Installing the packages 52 ## Installing the packages
46 53
47 Now that you have a pubspec, you can run `pub install`. You must 54 Now that you have a pubspec, you can run `pub install`. You must
48 run this command from the directory containing the pubspec.yaml file. 55 run this command from the directory containing the pubspec.yaml file,
56 which must be next to the entrypoint file (the file you pass
57 to the Dart VM or in your &lt;script&gt; tag).
49 58
50 {% highlight yaml %} 59 {% highlight yaml %}
51 cd your/app 60 cd your/app
52 $DART_SDK/bin/pub install 61 YOUR_DART_SDK_DIR/bin/pub install
53 {% endhighlight %} 62 {% endhighlight %}
54 63
55 This command creates a _packages_ directory inside the current directory, 64 This command creates a _packages_ directory inside the current directory,
56 cloning the git repositories into the packages directory. 65 cloning the git repositories into the packages directory.
57 66
58 The packages directory also contains any _transitive 67 The packages directory also contains any _transitive
59 dependencies_. 68 dependencies_.
60 For example, if the `awesome` package is dependent on the `sweet` package, 69 For example, if the `awesome` package is dependent on the `sweet` package,
61 the pub tool will also download and install the `sweet` package. 70 the pub tool will also download and install the `sweet` package.
62 71
63 ## Using libraries from the SDK 72 ## Using libraries from the SDK
64 73
65 <aside class="note"> 74 <aside>
66 <b>Note:</b> The functionality described in this section is temporary. 75 <div class="alert alert-info">
67 It's possible that some libraries 76 <strong>Note:</strong>
68 that currently ship in the SDK will be pulled out of the SDK and installable 77 The functionality described in this section is temporary.
69 directly from pub. 78 It's possible that some libraries
79 that currently ship in the SDK will be pulled out of the SDK and installable
80 directly from pub.
81 </div>
70 </aside> 82 </aside>
71 83
72 Not all libraries that ship with the SDK are available in the `dart:` 84 Not all libraries that ship with the SDK are available in the `dart:`
73 namespace. To use those libraries (for example, unittest) in your app, 85 namespace. To use those libraries (for example, unittest) in your app,
74 add an `sdk` source to your `pubspec.yaml` file. For example: 86 add an `sdk` source to your `pubspec.yaml` file. For example:
75 87
76 {% highlight yaml %} 88 {% highlight yaml %}
77 dependencies: 89 dependencies:
78 unittest: 90 unittest:
79 sdk: unittest 91 sdk: unittest
(...skipping 16 matching lines...) Expand all
96 and the Dart VM. 108 and the Dart VM.
97 109
98 If you use the `pub install` command, the packages directory is created 110 If you use the `pub install` command, the packages directory is created
99 for you next to the pubspec.yaml file. 111 for you next to the pubspec.yaml file.
100 112
101 ### Mapping packages for the Dart Editor 113 ### Mapping packages for the Dart Editor
102 114
103 To help the Dart Editor understand how to find packages, go to Preferences 115 To help the Dart Editor understand how to find packages, go to Preferences
104 and point the "Package directory" to `/path/to/your/app/packages`. 116 and point the "Package directory" to `/path/to/your/app/packages`.
105 117
106 <aside class="note"> 118 <aside>
107 <b>Note:</b> In the future, you'll be able to configure the packages 119 <div class="alert alert-info">
108 mapping per project, instead of globally. 120 <strong>Note:</strong>
121 In the future, you'll be able to configure the packages
122 mapping per project, instead of globally.
123 </div>
109 </aside> 124 </aside>
110 125
111 ### Mapping packages for the Dart VM 126 ### Mapping packages for the Dart VM
112 127
113 For command-line Dart applications that use packages, use the 128 For command-line Dart applications that use packages, use the
114 `--package-root` option to specify the packages location. 129 `--package-root` option to specify the packages location.
115 130
116 For example: 131 For example:
117 132
118 {% highlight bash %} 133 {% highlight bash %}
119 $DART_SDK/bin/dart --package-root=./packages/ app.dart 134 $DART_SDK/bin/dart --package-root=./packages/ app.dart
120 {% endhighlight %} 135 {% endhighlight %}
121 136
122 Note the required trailing slash when specifying the `./packages/` directory. 137 Note the required trailing slash when specifying the `./packages/` directory.
123 138
124 ## Importing libraries from packages 139 ## Importing libraries from packages
125 140
126 To import libraries found in packages, use the `package:` prefix. 141 To import libraries found in packages, use the `package:` prefix.
127 142
128 {% highlight dart %} 143 {% highlight dart %}
129 #import('package:awesome/awesome.dart'); 144 #import('package:awesome/awesome.dart');
130 {% endhighlight %} 145 {% endhighlight %}
131 146
147 The Dart runtime will take everything after `package:` and look it up
148 within the package-root location.
149
132 ## Additional options 150 ## Additional options
133 151
134 Run `$DART_SDK/bin/pub --help` for a list of commands. 152 Run `YOUR_DART_SDK_DIR/bin/pub --help` for a list of commands.
135 153
136 154
OLDNEW
« no previous file with comments | « src/site/docs/library-tour/index.markdown ('k') | src/site/docs/sdk/index.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698