OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 /// Transformer used for pub serve and pub build | 5 /// Transformer used for pub serve and pub build |
6 library web_components.build.web_components; | 6 library web_components.build.web_components; |
7 | 7 |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 import 'package:barback/barback.dart'; | 9 import 'package:barback/barback.dart'; |
10 import 'package:code_transformers/assets.dart'; | 10 import 'package:code_transformers/assets.dart'; |
(...skipping 14 matching lines...) Expand all Loading... |
25 {List<InitializerPlugin> extraPlugins: const []}) { | 25 {List<InitializerPlugin> extraPlugins: const []}) { |
26 var htmlImportRecorder = new HtmlImportAnnotationRecorder(); | 26 var htmlImportRecorder = new HtmlImportAnnotationRecorder(); |
27 var plugins = [htmlImportRecorder]..addAll(extraPlugins); | 27 var plugins = [htmlImportRecorder]..addAll(extraPlugins); |
28 | 28 |
29 // Bootstrap the application using the `initialize` package and our | 29 // Bootstrap the application using the `initialize` package and our |
30 // plugins. | 30 // plugins. |
31 var initializeBootstrap = generateBootstrapFile( | 31 var initializeBootstrap = generateBootstrapFile( |
32 resolver, transform, scriptId, newScriptId, | 32 resolver, transform, scriptId, newScriptId, |
33 errorIfNotFound: false, plugins: plugins); | 33 errorIfNotFound: false, plugins: plugins); |
34 | 34 |
35 // Add all seen imports to the document. | 35 // Add all seen imports to the document, before the first dart script tag if |
| 36 // it exists. |
| 37 var dartScript = |
| 38 document.head.querySelector('script[type="application/dart"]'); |
36 for (var importPath in htmlImportRecorder.importPaths) { | 39 for (var importPath in htmlImportRecorder.importPaths) { |
37 document.head.append(new dom.Element.tag('link') | 40 var import = new dom.Element.tag('link') |
38 ..attributes = {'rel': 'import', 'href': importPath,}); | 41 ..attributes = {'rel': 'import', 'href': importPath,}; |
| 42 document.head.insertBefore(import, dartScript); |
39 } | 43 } |
40 | 44 |
41 return initializeBootstrap; | 45 return initializeBootstrap; |
42 } | 46 } |
43 | 47 |
44 /// A [Transformer] which runs the `initialize` transformer with | 48 /// A [Transformer] which runs the `initialize` transformer with |
45 /// some special plugins and also inlines the html imports. | 49 /// some special plugins and also inlines the html imports. |
46 class WebComponentsTransformer extends Transformer { | 50 class WebComponentsTransformer extends Transformer { |
47 final Resolvers _resolvers; | 51 final Resolvers _resolvers; |
48 TransformOptions options; | 52 TransformOptions options; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 from: path.url.dirname(primaryInput.id.path)); | 128 from: path.url.dirname(primaryInput.id.path)); |
125 | 129 |
126 // Output the new document and bootstrap file. | 130 // Output the new document and bootstrap file. |
127 transform | 131 transform |
128 .addOutput(new Asset.fromString(primaryInput.id, doc.outerHtml)); | 132 .addOutput(new Asset.fromString(primaryInput.id, doc.outerHtml)); |
129 transform.addOutput(bootstrap); | 133 transform.addOutput(bootstrap); |
130 }); | 134 }); |
131 }); | 135 }); |
132 } | 136 } |
133 } | 137 } |
OLD | NEW |