问题
Is there an imperative way to bootstrap Polymer, in the style of Angular bootstrap?
The docs give details about individual elements lifecycle, but nothing about the framework itself.
I'm looking for a way to reconcile Polymer with requirejs and I need to force a single point of entry into my app. If I can bootstrap Polymer from within the requirejs data-main, I'm good.
related material:
- Working with Polymer and requirejs
- Require.js to load all resources for an app, including Polymer
- Polymer + requirejs: Attributes on were data bound prior to Polymer upgrading the element
- requirejs+polymer thread on google group
- polymer+requirejs gist
回答1:
I've figured out a simple way to manually trigger my app to bootstrap (at least it works for single page app), here's how you can do it too:
- Don't import any of your
custom-element.html
from theindex.html
or any other page directly imported from the index. Yourpolymer-ready
event should fire straight away but none of your custom elements will be loaded. This may require additional steps on your part to avoid FOUC and what not. - When you want to bootstrap your app, use the polymer.import helper function to kick things off. If you have a hierarchy of elements importing each other, you only need to manually import the top-level elements, the others will be imported through html imports. You can repeat this with different elements at different times if you want to import parts of your app dynamically.
来源:https://stackoverflow.com/questions/28673242/manual-bootstrap-in-polymer