1

在 Dart 编辑器(Pub Build (Generates JS)选项)中构建 Google Dart 网络应用程序后,文件夹布局如下所示。我的应用程序同时导入了两者dart:htmldart:async但似乎我可以将$sdk文件夹以外的所有内容上传到我的服务器,并且该应用程序将在 Dartium 和其他浏览器中运行良好。有什么原因我需要上传$sdk文件夹,它是做什么用的?尝试谷歌搜索,但我没有看到答案,提前谢谢!

编辑:这是我的 DartEditor 1.5.8 项目的一个工作示例,下面是它的代码。

hexclock.dart:

import 'dart:html';
import 'dart:async';
DateTime theTime;
String theHour, theMinute, theSecond;
Timer theTimer;
void main() {
  theTimer = new Timer.periodic(new Duration(seconds: 1), getTime);
}

void updateColours(){
  String bgcol = "#" + theHour + theMinute + theSecond;
  querySelector("body").style.backgroundColor = bgcol;
}

void printTime() {
  querySelector("#hour").text = theHour;
  querySelector("#minute").text = theMinute;
  querySelector("#second").text = theSecond;
}

void getTimeInit(){
  theTime = new DateTime.now();
  theHour = "${checkZero(theTime.hour)}";
  theMinute = "${checkZero(theTime.minute)}";
  theSecond = "${checkZero(theTime.second)}";
  printTime();
  updateColours();
}

void getTime(Timer t){
  theTime = new DateTime.now();
  theHour = "${checkZero(theTime.hour)}";
  theMinute = "${checkZero(theTime.minute)}";
  theSecond = "${checkZero(theTime.second)}";
  querySelector("#title").style.opacity = "0";
  querySelector("#clock").style.opacity = "1";
  printTime();
  updateColours();
}

String checkZero(int anInt){
  if (anInt < 10)
    return "0${anInt}";
  else
    return "${anInt}";
}

hexclock.html:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>HexClock</title>
    <script async type="application/dart" src="hexclock.dart"></script>
    <script async src="packages/browser/dart.js"></script>
    <link href='http://fonts.googleapis.com/css?family=Droid+Sans+Mono' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" href="hexclock.css">
  </head>
  <body> 
    <div id="title" class="centre">hexclock</div>
    <div id="clock" class="centre">#<span id="hour">&nbsp;&nbsp;</span><span id="minute">&nbsp;&nbsp;</span><span id="second">&nbsp;&nbsp;</span></div>
  </body>
</html>

pubspec.yaml:

name: HexClock
description: A sample web application
dependencies:
  browser: any
4

2 回答 2

2

pub 源代码中,我发现了这个:

  // "$sdk" is a pseudo-package that allows the dart2js transformer to find
  // the Dart core libraries without hitting the file system directly. This
  // ensures they work with source maps.
  var libPath = path.join(sdk.rootDirectory, "lib");
  var sdkSources = listDir(libPath, recursive: true)
      .where((file) => path.extension(file) == ".dart")
      .map((file) {
    var idPath = path.join("lib",
        path.relative(file, from: sdk.rootDirectory));
    return new AssetId('\$sdk', path.toUri(idPath).toString());
  });

我不知道这是否与您所看到的完全匹配,但我的猜测是它是相关的。这在理论上甚至可以通过 SDK 功能进行客户端调试,这可能非常有用。

于 2014-09-13T12:17:41.123 回答
1

基本上整个构建文件夹都打算被部署。
有一些冗余文件*.dart.pecompiled.js,例如只有 CSP 环境(例如 Chrome 应用程序)才需要的文件。
我认为最近发生了变化,因此不再生成这些文件。

可能还有其他多余的东西,但我还没有看到任何关于它的信息。

您可以尝试使用 Dart 1.6 版本(稳定版应该已经发布)并检查它是否已被删除或者是否必须有其他解释。
我总是使用目前 1.7+ 的bleeding_edge。

另一种解释是,这仅在您构建debug模式时创建。
DartEditor 默认执行此操作。

尝试pub build从命令行查看它是否仍然生成。

于 2014-09-13T12:17:47.707 回答