With Dart 1 I was able to specify some dart2js options in the transformers section of my pubspec.yaml, in particular, the option to make the resulting JS CSP-compliant:
transformers:
- $dart2js:
csp: true
How can I get the same thing in builder-land?
Add this configuration of the build_web_compilers builder to your build.yaml file:
targets:
$default:
builders:
build_web_compilers|entrypoint:
release_options:
dart2js_args:
- --csp
Other useful options include -O3 (compiler optimization level), --minify.
Related
I have an issue to mix several builders on single package.
In fact, I created build.yaml that contains the sources for file generation (JS builder), but when I need to test my web app (i.e. using build_web_compilers), it works only if I remove build.yaml file.
How to use both builders (JS builder + Web builder) without deleting/recreating build.yaml file ?
build.yaml
targets:
$default:
builders:
js_wrapping_generator|js_wrapping:
enabled: true
sources:
- 'lib/src/*.dart'
- 'example/*.dart'
builders:
js_wrapping:
target: "js_wrapping_generator"
import: "package:js_wrapping_generator/builder.dart"
builder_factories: ["jsWrapping"]
build_extensions: {".dart": [".g.dart"]}
auto_apply: dependents
build_to: source
Versions
Dart VM version: 2.0.0-dev.67.0
build_runner: ^0.9.1
build_test: ^0.10.2
build_web_compilers: ^0.4.0
source_gen: ^0.8.3
test: ^1.2.0
I have the following line in my pubspec.yaml file
transformers:
- di
- polymer:
entry_points: web/index.html
di package is imported as a depency - no problem there.
When I attempt an 'Upgrade Dependencies' the following error results
No dependencies changed.
Error on line 29, column 3 of pubspec.yaml: A transformer map must have a single key: the transformer identifier.
- polymer:
^^^^^^^^^
I have looked at other examples that seems similar to mine, including https://www.dartlang.org/tools/pub/assets-and-transformers.html#specifying-transformers but is unable to correct the error.
Thanks for helping.
Remove the indentation before the transformers like
transformers:
- di
- polymer:
entry_points: web/index.html
I have found Migration guide (https://www.polymer-project.org/1.0/docs/migration.html). My Dart project does not use bower but pubspec.yaml and when I changed dependencies version for PaperElements I get message: paper_elements has no versions that match >=1.0.0
environment:
sdk: '>=0.8.10+6 <2.0.0'
dependencies:
browser: '>=0.10.0+2'
code_transformers: any
core_elements: '>=0.6.0'
dnd: any
logging: '>=0.9.3'
paper_elements: '>=1.0.0'
polymer: any
polymer_intl: any
vector_math: any
transformers:
- polymer:
entry_points:
web/index.html
inline_stylesheets:
packages/polymer/src/build/log_injector.css: false
- $dart2js:
minify: true
How to upgrade?
update
https://pub.dartlang.org/packages/polymer_elements
(ignore the deprecated comment in the readme)
original
There are no 1.0 elements for Dart yet.
This is work in progress and before they are not published there is no way to use them the way you did previously.
You can use the Polymer.js elements in the meantime of course but then you have to use bower and dart-js-interop.
I am trying to get packages from the PUB with the following:
name: 'ch_padart'
version: 0.0.1
dependencies:
angular: "1.1.0"
angular_node_bind: any
polymer: ">=0.15.5+2 <0.16.0"
core_elements: ">=0.6.0+4 <0.7.0"
paper_elements: ">=0.6.1 <0.7.0"
web_components: ">=0.9.0 <0.11.0"
browser: ">=0.10.0+2 <0.11.0"
dev_dependencies:
unittest: ">=0.11.0+5 <0.12.0"
mock: ">=0.11.0+2 <0.12.0"
transformers:
- angular:
html_files:
- web/index.html
- polymer:
entry_points: web/index.html
lint: false
but the end result is always 'Connection closed before full header was received'
If you remove angular OR polymer (and elements) and then run pub get, there is no issue and all download and runs fine. No other warnings are displayed and --verbose yields nothing helpful that I can see.
When you run pub get -v from command line you will see that pub is working quite hard but can't find a compatible set of dependencies. There was a similar issue recently that the I guess the collection package was required in different dependencies with non-overlapping version constraints.
This is quite common when using Angular with Polymer.
You might need to investigate the dependencies manually to find the cause.
Maybe you get some feedback from pub get when you remove all dependency constraints and then start adding them again one by one.
the pubviz packages helps to resolve this kind of issue as well: https://pub.dartlang.org/packages/pubviz
I written a website using dart and polymer, it runs well in Chromium, but cannot get it compiled to js.
The directory layout is like:
my_proj/
pubspec.yaml (Contents below)
lib/
some_code.dart ... (Used by index.dart, app.dart and custom_elem_x.dart)
asset/
3rd-party codes ... (CSS, JS lib, etc.)
web/
index.html (Traditional HTML, no polymer stuff)
app.html (Use lots of custom elements written in polymer)
script/
index.dart (Pure dart, nothing fancy, has a main())
app.dart (Has a main(), in which initPolymer() get called)
polymer/
custom_elem_1.html (Imported by app.html via \
custom_elem_1.dart <link rel="import" href="polymer/custom_elem_1.html">)
...
custom_elem_n.html
custom_elem_n.dart
pubspec.yaml:
name: blah
dependencies:
browser: any
polymer: any
...
transformers:
- polymer:
entry_points: web/app.html
- $dart2js:
minify: true
If I run pub build under my_proj/, there is no error as far as I can tell, (lots of warnings, though). But the index.html is static (just contents, no actions), and the custom element in app.html is not rendering. Any idea what caused this?
I am using dart-sdk 1.2.1 (pub --version) on Debian 7 32bit.
Thanks.
Edit
Managed to fix it by deleting all packages/ in project dir, and running pub get again. custom_element, shadow_dom, html5lib get updated to 0.9.2, seems these updates got it fixed, because I put get several times before, and nothing worked.