簡體   English   中英

如果Dart和JS文件都在頁面中鏈接,那么Dartium中將運行什么代碼?

[英]What code wiill run in Dartium if both Dart and JS files are linked in the page?

我有一個指向dart源文件的鏈接,以開發和調試我的應用程序,還有一個指向JS bundle文件進行生產的鏈接。

我考慮將它們像這樣組合在一起:

<script type="application/dart" src="app.dart"></script>
<script src="app.js"></script>

我想普通的瀏覽器會忽略第一個鏈接,而使用第二個。 但是,其中哪些將在Dartium中運行?

我應該將它們放在一起還是應該動態地將dart開發和js放到發行版中?

推薦的方法是在頁面中包含以下標記:

<script type="application/dart" src="app.dart"></script>
<script src="packages/browser/dart.js"></script>

dart.js文件用於檢查對Dart的本機支持,並下載Dart腳本或加載已編譯的JS。 請參閱此頁面以獲取更多信息: https : //www.dartdocs.org/documentation/browser/0.10.0%2B2/

構建用於部署的應用程序時,應將2個標記替換為Javascript版本。

<script src="app.dart.js"></script>

您可以使用dart_to_js_script_rewriter轉換器自動執行此dart_to_js_script_rewriter 參見https://pub.dartlang.org/packages/dart_to_js_script_rewriter

為此,您應該在pubspec.yaml擁有此pubspec.yaml

dependencies:
  browser: any
  dart_to_js_script_rewriter: any
transformers:
- dart_to_js_script_rewriter

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM