2

I want to server a Dart application on an Apache server. I added the line

application/dart dart

to the mime.type file in the Apache configuration. Still I get the error

Resource interpreted as Script but transferred with MIME type text/plain:    "http://localhost/~d022051/mastermind/web/mm-game.dart".

Another issue is the link to the packages directory. I do not want to have symlinks in the documents directory of the server. Is there a smart way to copy the required packages in the correct version?

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
Gregor
  • 2,917
  • 5
  • 28
  • 50

2 Answers2

3

This message has nothing to do with Apache.

It's a while that I worked with Apache, but as far as I know you don't need specific settings to serve a Dart client app using Apache. They are just like any other static HTML, CSS, JavaScript, or image files.

You get this message because the entry page (index.html) contains a script tag for a Dart script. After you run pub build there are no Dart scripts (yet) in the build output (this will change when Chrome supports Dart and pub build also generates Dart output).

When the browser finds this (currently redundant) Dart script tag it produces this output. When you want to get rid of this message just remove the script tag from the HTML page in your your_app_package/build/web/index.html file.

EDIT

transformers:
- $dart2js:
    'minify': true
    commandLineOptions: ['--output-type=dart']

or

    commandLineOptions: ['--output-type=dart', '--categories=Server']

I haven't tested if this categories argument has an effect in dart2dart too.

EDIT END

EDIT2

There is also the output type dart-multi which creates one output file per input library. See https://code.google.com/p/dart/issues/detail?id=21616#c9 for more details.

EDIT2 END

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • Hi, the dart.js file is only part of the problem. The real problem is to get the right packages, with the right versions and the right names, with the right internal structure and the right permissions to the docs directory of the server. Is there nothing that packages the dart sources for delivery on a server? – Gregor Jul 10 '14 at 10:45
  • I don't know what you mean with permissions but normally you only need to copy the `build/web` directory (or just its content) to the docs directory after running `pub build`. – Günter Zöchbauer Jul 10 '14 at 10:47
  • I'm talking about running the dart scripts in Dartium. The packages within the build directory only contain js files, no dart. The packages in the project root are links to the .pub-cache. There the packages haven't set the x-bit for any user. And these packages have the dart files in a lib directory, which is not part of the used urls. – Gregor Jul 10 '14 at 10:59
  • You should have mentioned this. Dartium is not for production so this can only be a development setup. Why do you need this? I guess you need to forward/delegate Dart related requests to `pub serve` instead to a static directory. – Günter Zöchbauer Jul 10 '14 at 11:01
  • Sorry, I thought "Dart application" would make this clear. I want to run the app internally and share it with our dev team. – Gregor Jul 10 '14 at 11:06
  • I updated my answer. You can try to add `--output-type=dart` to produce Dart output (I have never used this myself yet - I just tried it with some random project before extended my answer). But I still can't understand why you need Dart to share it with your dev team. Why not share the build JS output? – Günter Zöchbauer Jul 10 '14 at 11:24
  • 1
    @Gregor `--output-type=dart` might be deprecated. If it doesn't work you can create dummy transformer that simply passes through itself files with the `.dart` extension. – JAre Jul 10 '14 at 12:40
  • Unfortunately pub build --output-type=dart is not a known option. – Gregor Jul 10 '14 at 15:36
  • I tried it and `pub build` generated `*.html` output with inlined Dart code. I didn't try if the generated code actually worked but I had to fiddle a while to figure out the format for `pubspec.yaml` to make it work. I used `Dart VM version: 1.6.0-edge.38118 (Thu Jul 10 05:58:06 2014) on "linux_x64"`. You can try `dart2js -hv` to get a list of supported options. – Günter Zöchbauer Jul 10 '14 at 15:39
  • I will try out the transform option. Thanks for your hint. – Gregor Jul 10 '14 at 15:42
  • @Gregor you can remove source formatting, comments and, might be, some type annotations in transformer with the `analyzer` pub packages. It can parse string and build dart AST from it. You can find all irrelevant AST nodes(comments are nodes) and delete them. Then you can build new source from it (`analyzer` provides this functionality) It's in experimental stage but works pretty well. – JAre Jul 10 '14 at 16:43
  • The output type option for the transformer did indeed build a web app using the dart files. It can be copied to a folder served by the Apache httpd and is runnable in Dartium. One additional remark: you have to add the option --mode=debug on the command line. Otherwise there will be no dart sources in the build directory. – Gregor Jul 11 '14 at 14:26
  • Didn't think of that. Without `--mode=debug` the code is inlined into the HTML files and with `debug` the source files are created separately. So your issue is solved then? Glad to hear. – Günter Zöchbauer Jul 11 '14 at 14:28
0

Add the following lines to the pubspec.yaml file of your package (thanks to Günter, who pointed this out):

transformers:
- $dart2js:
    'minify': true
    commandLineOptions: ['--output-type=dart']

Then run pub build with the option --mode=debug.

This results in a "runnable" Dart application, containing the dart sources and the needed packages. The build directory can then be copied to a location visible to your web server. When loading the corresponding URL in the Dartium browser the application is started.

Gregor
  • 2,917
  • 5
  • 28
  • 50