In this step, you'll deploy your application to the web.
Build for deployment
Run the following Polymer CLI command to perform a number of steps to prepare your application for deployment:
polymer build
This command minifies the HTML, JS, and CSS dependencies of your application, and generates a service worker that precaches all of the dependencies of your application so that it can work offline.
The built files are output to the following folders:
build/unbundled. Contains granular resources suitable for serving via HTTP/2 with server push.build/bundled. Contains bundled (concatenated) resources suitable for serving from servers or to clients that do not support HTTP/2 server push.
Deploy to a server
Polymer applications can be deployed to any web server.
This template utilizes the <app-location> element to enable URL-based routing,
which requires that the server serve the index.html entry point for all
routes.
You can follow one of the sections below to deploy this app to either Google AppEngine or Firebase Static Hosting, which are both free and secure approaches for deploying a Polymer app. The approach is similar for other hosting providers.
Deploy with AppEngine
-
Download the Google App Engine SDK and follow the instructions for your platform to install it.
-
Open the project dashboard and create a new project
- Click the Create Project button.
- Type a project name.
- Click the Create button.
-
cdinto your project directory. -
Create an
app.yamlfile and instruct the server to serve upindex.htmlfor any URL's that don't otherwise end in a file extension. Replace{project name}with the name you chose in the previous step.application: {project name} version: 1 runtime: python27 api_version: 1 threadsafe: yes handlers: - url: /bower_components static_dir: build/bundled/bower_components secure: always - url: /images static_dir: build/bundled/images secure: always - url: /src static_dir: build/bundled/src secure: always - url: /service-worker.js static_files: build/bundled/service-worker.js upload: build/bundled/service-worker.js secure: always - url: /manifest.json static_files: build/bundled/manifest.json upload: build/bundled/manifest.json secure: always - url: /.* static_files: build/bundled/index.html upload: build/bundled/index.html secure: always -
Deploy.
appcfg.py -A {project name} update app.yaml
Deploy with Firebase
The instructions below are based on the Firebase hosting quick start guide.
-
Install the Firebase command line tools.
npm install -g firebase-toolsThe
-gflag instructsnpmto install the package globally so that you can use thefirebasecommand from any directory. You may need to install the package withsudoprivileges. -
cdinto your project directory. -
Inititalize the Firebase application.
firebase login firebase initFirebase asks you which app you would like to use for hosting. If you just signed up, you should see one app with a randomly-generated name. You can use that one. Otherwise go to https://www.firebase.com/account to create a new app.
-
Firebase asks you the name of your app's public directory. Enter
build/bundled. This works because when you runpolymer buildto build your application, Polymer CLI places your bundled application appropriate for serving on Firebase into thebuild/bundledfolder. -
Edit your firebase configuration to add support for URL routing. The final
firebase.jsonfile should look something like this:{ "hosting": { "public": "build/bundled/", "rewrites": [ { "source": "**/!(*.*)", "destination": "/index.html" } ] } }This instructs Firebase to serve up
index.htmlfor any URLs that don't otherwise end in a file extension. -
Deploy.
firebase deployThe URL to your live site is listed in the output.