I'm a bit confused as to how to build a Polymer Element 1.x, scaffolded by running $ polymer init
What I did so far:
Run $ polymer init
Coded my element in ES6 without changing any of the directory structure/paths.
Run $ polymer build
Current project structure
It's identical to the structure created by running $ polymer init with no changes whatsoever in the directories/path references.
/bower_components
/demo/index.html
/test/my-element_test.html
/test/child-element_test.html
my-element.html
child-element.html
bower.json
polymer.json
index.html
README.md
Goal is to create ES5 versions of the elements.
I'd like to create built versions of my element, transpiled from ES6 to ES5.
Ideally my project structure would look like this:
/bower_components
/demo/index.html
/build/bower_components
/build/my-element-es5.html
/build/child-element-es5.html
/test/my-element_test.html
/test/child-element_test.html
my-element.html
child-element.html
bower.json
polymer.json
index.html
README.md
Running $ polymer build only creates a build/default/index.html, which only contains an <iron-component-page> referencing my element.
Does $ polymer build work on single elements created with $ polymer init or is it just for app-style projects?
If it does work for pure elements, what am I missing here?
Note: My element 'project' contains 2 elements, my-element.html and child-element.html.
Actually it seems $ polymer build is not supporting Polymer Element projects at all.
See this Issue for more info and watch this S.O post on how to do single element transpilation
Related
I wish to use polymer to create a web component and embed it in another project built with angular.js.
The same way we can do with stencil, where I can just import a script and use the web components.
I tried following the official polymer tutorial, but it only specifies how to build a "polymer app", I wish to have a component, bundled into a single JS file.
I tried running these commands with polymer CLI.
polymer init
polymer build
I got an HTML file, but the source component was not compiled or bundled.
I expected a compiled version of the component which I can use in any other project - like I get when I compile stencil.
Here are some useful links for you
https://medium.com/#tonytunes2005/integrating-polymer-3-components-on-angular-5-317f8c43ef03
https://medium.com/google-developer-experts/mix-and-match-angular-custom-elements-polymer-1aee0b3d63a1
https://vaadin.com/blog/using-polymer-components-in-angular-2
I am developing a web component using Polymer v3, and need to include some custom elements defined in legacy Polymer 2 components in the template HTML of my new component.
Since HTML imports are no longer supported in Polymer 3, what approach should I take to include them? If I was using Polymer 2 I could just add the following in my component's HTML file:
<link rel="import" href="../my-legacy-component.html">
I have tried adding the above link into the template HTML of my component, but it appears that doesn't work. I have also tried various import commands to reference the JS files inside the legacy component directly, but received various inscrutable JS errors so I'm not sure if that is the correct way to go either.
I can't believe there isn't a simple way to do this - would the Polymer team really introduce a new version of the library that is completely incompatible with all the components created using older versions?
Did you try to use polymer-modulizer?
Modulizer performs many different upgrade tasks, like:
Detects which .html files are used as HTML Imports and moves them to .js
Rewrites in HTML to import in JS.
Removes "module wrappers" - IIFEs that scopes your code.
Converts bower.json to package.json, using the corresponding packages on npm.
Converts "namespace references" to the proper JS module import, ie: Polymer.Async.timeOut to timeOut as imported from #polymer/polymer/lib/util/async.
Creates exports for values assigned to namespace referencs. ie, Foo.bar = {...} becomes export const bar = {...}
Rewrites namespace objects - an object with many members intended to be used as a module-like object, to JS modules.
Moves Polymer element templates from HTML into a JS template string.
Removes s if they only contained a template.
Moves other generic HTML in the document into a JS string and creates it when the module runs.
more on github
I have ran into the same problem with the module js-yaml earlier. I don't have enough reputation for a comment yet so I just write it down here.
Run this sudo npm install -g js-yaml -> This will install the missing package for the tool
Then at the root of your project, run modulizer --import-style name --out . -> This will convert your component from Polymer 2 to Polymer 3. The option --import-style name tells the tool to use package name instead of path. --out will make the tool writes those files to the directory.
After that, if no error prompts. Try to serve it with polymer serve --module-resolution=node -> Since we are using node modules now, we have to provide the --module-resolution=node option.
How to install polymer iron and paper elements for Polymer 0.9 using bower? Tried using bower to install in a way similar to core-elements but fails. Migration guide doesn't provide any information on upgrading core/iron or paper elements.
bower install Polymer/iron-elements#^0.9.0
bower iron-elements#^0.9.0 not-cached git://github.com/Polymer/iron-elements.git#^0.9.0
bower iron-elements#^0.9.0 resolve git://github.com/Polymer/iron-elements.git#^0.9.0
bower iron-elements#^0.9.0 ECMDERR Failed to execute "git ls-remote --tags --heads git://github.com/Polymer/iron-elements.git", exit code of #128 fatal: remote error: Repository not found.
The new 0.9 elements are here.
You get them with bower this way:
bower install polymerelements/iron-ajax
I don't think there's an entire element collection ready yet, you should probably download every single needed element.
You can find more info about the new elements in the 0.9 release info:
Where did the elements go?
Not all elements have been ported to the
current release, but we’re porting them as fast as we can. You can
find work-in-progress versions of many elements in the PolymerElements
GitHub organization.
The elements are being reorganized into more consistent product lines,
including:
Iron elements. Basic elements that don’t express a visual style. Most
of the old core- elements are being renamed to iron-. Some former
core- elements that implemented material design (such as core-toolbar,
core-menu, core-header-panel) are being migrated to paper-.
Paper elements. Material design elements. All of the old paper-
elements, plus a few of the old core- elements.
Neon elements. Animation elements.
These element sets will be launching with their own site sometime
around the Polymer 1.0 timeframe. The new site will include API docs
for the elements. If you want to get started with the work-in-progress
versions, the individual repos are the best source for information
about the elements right now.
You can also check out the community Road to Polymer project which is
tracking the status of Polymer elements.
Also, you may find some valualble info in the Polymer Blog. Stay tuned!
Thanks Matteo. Adding to Matteo's answer we can install all available ported iron and paper elements for Polymer 0.9.0 using the following bower commands
bower install polymerelements/iron-elements
bower install polymerelements/paper-elements
for any elements installation, first go to element's page:
https://elements.polymer-project.org/
and find the element you want. while inside the element's page, in the left hand side, there is 'Bower Command' section.
just copy that and paste it in your shell/terminal/command prompt.
I had the same error as you reported, and was unable to install any elements using bower as proposed above. However, everything worked after running following command in my project folder:
git config --local url."https://".insteadOf "git://"
Here you may find more details about this solution:
Bower Install error: Unable to connect & exit code of #128
Polymer dist/ folder has a single html file https://github.com/Polymer/polymer/tree/master/dist with a HTML import and a script tag. Most of the polymer elements doesn't even have a dist folder. Wouldn't it be a good practice to provide a single distribution bundle file like polymer.js and do the same for each polymer element available there?
There are some obvious advantages with this approach:
1. Minimum http requests to get the polymer core or a polymer element.
2. Easy to use for the clients, just include the required element.
Example: Elements that depend on other shared elements,
- shared-element: /webcomponents/font-roboto/roboto.js
- custom-element1: uses shared-element
- custom-element2: uses shared-element
An app using custom-element1 and custom-element2 downloads /webcomponents/font-roboto/roboto.js
only once with a single http request.
<script src="../webcomponents/webcomponentsjs/webcomponents.js"></script>
<script src="../webcomponents/custom-element1/custom-element1.js"></script>
<script src="../webcomponents/custom-element2/custom-element2.js"></script>
PS: the above custom-element1.js does the same thing as custom-element1.html expect that it is convenient to programmatically load and access the component.
I would like to hear from polymer team or other polymer developers/users on the best practices they are following to solve this.
If I'm understanding you correctly, what you want is Vulcanize.
As of the time of this writing, for polymer 1.0, the instructions are:
If you have an input HTML file, elements.html, that uses a number of HTML imports, you can run it through Vulcanize as follows:
vulcanize elements.html -o elements.vulcanized.html
The -o or --output flag will direct the output to a new file called elements.vulcanized.html. If you omit the -o flag, Vulcanize will print the output to stdout, which can be useful if you want to pipe it to another command.
elements.vulcanized.html now contains a version of elements.html with all imports inlined and dependencies flattened. Paths to any URLs are automatically adjusted for the new output location, with the exception of those set in JavaScript.
You can pass additional options to Vulcanize in the form of flags. For a full list of supported flags, see the official Vulcanize documentation.
Here’s the same example from above. The extra flags tell Vulcanize to strip out comments, and to merge external scripts and CSS files into the vulcanized file.
vulcanize -o elements.vulcanized.html elements.html --strip-comments --inline-scripts --inline-css
https://www.polymer-project.org/1.0/tools/optimize-for-production.html
It seems that you have to manually checkout a bunch of repos, and when I tried to run the core-tests runner.html, they reference htmls from outside the folder which is restricted by the browser
Polymer uses a notion of components. We define a component as a set of shareable resources in a folder. All of your components should be together in one master folder (I usually call it components). This way one component can reference another component by looking in ../<component-name>/.
A project will generally look something like this:
my-project/
index.html
components/ <-- could be symlink or a server redirection
platform/ <-- polyfills
polymer/ <-- polymer
core-ajax/ <-- a custom element
...
core-tests in particular, is itself a component. It lives in the components folder and runs tests on other components (by looking at ../<component-name>/ as above).
So, if your web-root in the example above is my-project, you should be able to access my-project/components/core-tests/runner.html to run those component tests.
There are multiple ways to populate the components folder. The easiest way is to use Bower (http://bower.io) with a command like bower install Polymer/core-elements.
You can also use Git checkouts, or ZIP archives. There is a nifty utility for downloading Bower packages as zip files at bowerarchiver.appspot.com. E.g.:
http://bowerarchiver.appspot.com/archive?core-elements=Polymer/core-elements
Will get you a zip of the core-elements Polymer component, with all of it's dependencies.
There are two Yeoman generators that can help you with starting off: yo polymer and yo element
yo polymer is based on the polymer seed-element and yo element is based on the polymer-boilerplate.
I ended up writing a blog post on getting the hang of these different setups. If you get the latest version of the generator from the github repo it will scaffold an app for you:
npm install -g git+https://github.com/yeoman/generator-polymer.git
Also make sure to have a look at the vulcanize task to concat your components.