Using Integration with the Pub Tool
On this page:
- Managing Dart dependencies
- Building a Dart application
You can also use the pub tool in the command line mode from the embedded local terminal.
Execution of the pub tool commands is logged in the Messages Tool Window. In this tool window, you can examine the tool log and re-run the last executed command by clicking on the toolbar.
Managing Dart dependencies
IntelliJ IDEA provides interface for running the pub get
and pub upgrade actions from the editor.
As soon as you open a pubspec.yaml file in the
editor, IntelliJ IDEA displays a Pub actions pane at the top of the
editor tab. You can use the links on this pane or use the context menu of the editor or the
pubspec.yaml file in the Project tool window.
The pub tool saves the downloaded packages in caches, creates a
folder next to the
pubspec.yaml file which contains information on packages and their
dependencies. In the
web folder, the pub tool creates a copy of the
packages folder. As soon as a subfolder if created under the
a copy of the
packages folder is created in the new subfolder.
All the copies of the
packages folder are automatically excluded from the project, that is, they
are not indexed. IntelliJ IDEA excludes these copies on opening a project and every time the
pub get or pub upgrade action is invoked.
All the excluded copies
packages folder are listed in the exclusion list in the Sources Tab
on the Module Page of the Project Structure Dialog.
You can remove a copy from this list but the copy will be restored during the first automatic exclusion.
To download or upgrade dependencies:
- Open the
pubspec.yamlfile in the editor.
- To detect and download dependencies, do one of the following:
- To download the up-to-date versions of the existing dependencies, do one of the following:
If for some reasons the previously downloaded and stored in a cache dependencies are broken, you can clear the cache and download the dependencies anew:
When running and debugging Dart web applications, IntelliJ IDEA uses the Pub Serve tool.
Integration with it is established through the built-in server which acts transparently as a proxy server
between your application and the Pub Serve tool.
In other words, integration with the Pub Serve tool works invisibly and you do not need to care about it.
The tool is invoked automatically when you run or debug a Dart web application, either by opening an HTML file or by launching a run/debug configuration.
The tool analyzes the
<script></script> element in the HTML file. If the element references a Dart file, Pub Serve invokes the Dart2js compiler
The work of the Pub Serve tool is logged in the dedicated Pub Serve tool window which opens when you start running or debugging a Dart web application for the first time during the current IntelliJ IDEA session. You can stop the tool by clicking on the toolbar. As soon as you start running or debugging again, the tool restarts automatically.
See Running and Debugging Dart Web Applications for details.
Building a Dart application
IntelliJ IDEA provides interface for using the pub tool which
builds applications through the pub build
using the dart2js,
and stores all the output in the automatically created
build folder. The folder is marked as
excluded, see Configuring Folders Within a Content Root.
See Assets and Transformers for details.
To build a Dart application:
- Open the
pubspec.yamlfile in the editor or switch to the tab where it is opened.
- On the pub pane at the top of the tab, click Build.
- In the dialog box that opens, choose the build mode which determines the behaviour of the
- Release: choose this option to have dart2js minify the
new lines, comments without affecting the functionality of the source code.
In the Release mode, the source
.dartfiles are not included in the build output. This mode is applicable when you are going to publish your application.
as well as the source
- Other: choose this option if you want to use a custom transformer and specify the path to it.