How To Build and Deploy Dart App With Client and Server Code
-
27-12-2019 - |
Pergunta
I am new to Dart. I created a simple web app with client and server code. My app directory structure is as follows:
MyProject
pubspec.yaml
build.dart
Procfile
server.dart
/web
client.html
client.dart
The following is the contents of build.dart, which was generated automatically by DartEditor
import 'package:polymer/builder.dart';
main(args) {
build(entryPoints: ['web/client.html'],
options: parseOptions(args));
}
Can I build both the client and server using one build.dart? How can I build my server.dart along with the client side?
Solução
Your server, which I'm assuming is similar to an HTTP server to be used via CLI or run as a daemon on a server somewhere else, does not need to be built. The build process run through the dart2js compiler and generate javascript output. In this case, your server should be run by the Dart VM and need not be compiled.
Most likely you would just want the server to serve files from the build/ directory. Additionally since the pub command can now build Polymer files, it is recommended to use pub build as opposed to the build script for building your files. Just ensure you add these 3 lines to your pubspec.yaml file:
transformers:
- polymer:
entry_points: web/client.html