Minimal steps required to create a custom elemenet in Polymer 1.0, without any aid from tools like Yeoman and Gulp.
I have used the Quick tour of Polymer as a reference.
- Install Node.
- Install a light weight HTTP server
npm install -g serve
Description | Command_____________________________ |
---|---|
Install or update Bower | npm install -g bower npm update -g bower |
Create a project folder | mkdir my-project cd my-project |
Init a new project with Bower | bower init |
Install Polymer + web-components | bower install --save Polymer/polymer |
Create file for the custom element and append code listed below |
touch greeting-element.html |
Create index.html and append code listed below |
touch index.html |
Start the HTTP server | serve |
... or, if you're on a Mac, you can instead use the python SimpleHttpServer | python -m SimpleHTTPServer 3000 |
Open browser with URL | http://localhost:3000/ |
Output should be | Hello Stranger! Hello Leif! |
Updating packages | bower update |
Code to create the custom element.
<link rel="import" href="bower_components/polymer/polymer.html">
<dom-module id="greeting-element">
<style>
:host {
display: block;
}
h1 {
color: blue;
}
</style>
<template>
<h1>Hello <span>{{greeting}}</span>!</h1>
</template>
<script>
Polymer({
is: 'greeting-element',
properties: {
greeting: {
type: String,
value: "Stranger"
}
}
});
</script>
</dom-module>
Import the greeting-element, <link rel="import" href="greeting-element.html"></link>
, into index.html and start your custom element.
<!DOCTYPE html>
<html>
<head>
<title>Example Polymer custom element</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=yes">
<script src="bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
<link rel="import" href="greeting-element.html"></link>
</head>
<body>
<greeting-element></greeting-element>
<greeting-element greeting="Leif"></greeting-element>
</body>
</html>
Using the Yeoman element generator requires us to follow the folder layout from a Yeoman generated Polymer project. So before we can create a Yeoman element, we must scaffold a new Polymer project using generator-polymer
.
As an alternative to using Yeoman to scaffold your project, you can download the Polymer Starter Kit and skip the next section.
generator-polymer
is a scaffolding tool for Yeoman, which generates a sample Polymer 1.0 project using Polymer Start Kit, letting you easily create and customize Polymer (custom) elements via the command-line and import them using HTML Imports. This saves you time writing boilerplate code so you can start writing up the logic to your components straight away. Use the following steps to set up a new Polymer app, generating all the boilerplate you need to get started.
Description | Command______________________________ |
---|---|
Install or update tools | npm install -g yo bower grunt-cli npm update -g yo bower grunt-cli |
Install or update gulp | npm install -g gulp npm update -g gulp |
Install or update Yeoman generator for Polymer projects | npm install -g generator-polymer npm update -g generator-polymer |
Create a project folder | mkdir my-project cd my-project |
Sets up a new Polymer app | yo polymer |
Start the HTTP server | gulp serve |
Open browser with URL | http://localhost:3000/ |
A short introduction to generator-polymer
is provided here: Setting up your Production-ready Polymer 1.0 Application Development
Description | Command______________________________ |
---|---|
Generate element. | yo polymer:el yo-greeting-element |
The generated element,yo-greeting-element.html is created in folder./app/elements/yo-greeting-element If you don't wish to use the standard folder layout, go ahead and move the generated element to another folder (but remember to update the href in line 1 of the generated html). |
Generates a reusable polymer element based on the seed-element workflow. This should only be used if you're creating a standalone element repo that you intend to share with others via bower. If you're just building a Polymer app, stick to the Element generator.
Description | Command______________________________ |
---|---|
Install or update tools and Polymer generator | npm install -g yo bower grunt-cli npm update -g yo bower grunt-cli |
Install or update Yeoman generator for Polymer projects | npm install -g generator-polymer npm update -g generator-polymer |
Create a project folder | mkdir my-project cd my-project |
Scaffolding Polymer seed-element | yo polymer:seed my-seed-element |
Install Polyserve | npm install -g polyserve npm update -g polyserve |
Start Polyserve | polyserve |
Open browser at localhost:8080/components/my-seed-element/ |
|
Publish to reusable element to github |
Command_______________________________________ | Description |
---|---|
bower init | Create new project in working dir |
bower install | Install package dependencies from bower.json in working dir |
bower install polymer --save | Polymer + web-components. Always on an new project |
bower install polymerelements/paper-elements --save | Install and add add package dep to bower.json in working dir, |
bower install polymerelements/iron-elements --save | All elements in package iron-elements. |
bower install --save PolymerElements/paper-button | One particular element. |
bower info polymerelements/paper-elements | Package info |
bower info GoogleWebComponents/google-map | Component info |
bower update | Update package dependecies in project |
bower uninstall paper-elements --remove | Remove package from project |
bower uninstall paper-icon-button --remove | Remove component from project |
bower list polymerelements/paper-elements | Show package info |
bower list paper-icon-button | Show component info |
bower search | Search bower db for dependency, e.g. bower search jquery |
bower prune | Uninstall dependencies not listed in bower.json. As an alternative; just delete the bower_components folder and run bower install |
bower register <component> git://github.com/<user>/<component>.git | Register component, see: http://bower.io/docs/creating-packages/#register |
bower info | Get info about registered component |
- Polymer 1.0
- Material design
- Videos
- Polymer Starter Kit, Polycasts #18
- Polymer 1.0 Tutorials, Level Up Tutorials
- Polymer Lessons, Samuel Lespes Cardillo
- Learn Polymer 1.0, Stretch Projects
- Polymer 1.0 Tutorial Web app development, by Omege X
- Introducing the Polymer Designer tool
- Polycasts
- Material Design as Fast As Possible
- Making Material Design
-
- The ServiceWorker: The network layer is yours to own
- DevTips
- Articles / Blogs / etc
- Material Design Icons, Goodies and Starter Kits
- Sketch With Material Design
- Get Up and Running with Google Polymer 1.0 – In minutes!
- Setting up your Production-ready Polymer 1.0 Application Development
- Hands On With Polymer 1.0
- Polymer: The magic for creating your own web components
- Creating a Polymer Chat App with Material Design
- Material Design Blog
- Built with Polymer
- Road to Polymer
- Building a Credit Card Form Custom Element with Polymer
- Polymer Web Components Tutorial
- Plymer 1.0 Flex layout
- etc
- Material Design Animations Collection, with HTML/CSS/JavaScript, on CodePen
- Material Design Playground
- Animations in action
- Free Material Design Ui Kit
- Freebie: Smashicons Icon Set (500 Icons, 4 Styles, AI, PSD, Sketch)
- Polyfills
- The offline cookbook, Serviceworkers i JavaScript
- Introduction to Service Worker
- Service Workers in Polymer
-
- Google Closure Library
- Ramda
- Become A Command-Line Power User With Oh-My-ZSH And Z
- Commandline Power User
- iTerm2
- Oh My ZSH!