Run Dart WebApp on Apache Server

北战南征 提交于 2019-11-27 04:49:01

问题


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?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/24672090/run-dart-webapp-on-apache-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!