Dart Cookbook
上QQ阅读APP看书,第一时间看更新

Publishing and deploying your app

There comes a point in time where you consider your app to be production ready, and you are eager to hand it over to your clients or users. If it is a web app in the Dart world at this moment in time, this means compiling to JavaScript. Luckily, the pub tool will take care of this stage in your app's life, so that your app can be deployed successfully.

Getting ready

This is pretty straightforward. To prepare, you need to run and test your application in both the checked and production modes.

How to do it...

Run the pub build command (see the Compiling your app to JavaScript recipe in Chapter 1, Working with Dart Tools), either from the command line or in Dart Editor. This creates the build folder with the subfolder bin or web, respectively, for a command-line or web application. The build folder contains complete deliverable files. The files generated in there can be deployed like any static content. Upload the JavaScript files together with the web pages and resources to any production web server.

How it works...

The pub build command is Dart's optimized command to create the deployment assets. It performs tree shaking so that only the code that is necessary during execution is retained, that is, functions, classes, and libraries that are not called are excluded from the produced .js file. The minification process further reduces the size of the file by replacing the names of variables, functions, and so on with shorter names and moving the code around to use a few lines.

There's more...

Some application hosting sites to run your app in the cloud are as follows:

Once your app is ready to be shared with other developers, it can also be published to the pub repository (verify the contents of your pubspec.yaml configuration file and the app's folder structure. For more detailed information, refer to https://www.dartlang.org/tools/pub/publishing.html.