Skip to content

Instantly share code, notes, and snippets.

@searleb
Last active April 15, 2017 22:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save searleb/036c88d07f6690981bcdee0ac192b5a6 to your computer and use it in GitHub Desktop.
Save searleb/036c88d07f6690981bcdee0ac192b5a6 to your computer and use it in GitHub Desktop.
Setting up Polymer with Laravel

Setting up Polymer with Laravel

This guide will help you get a starting point for implementing Polymer into a default install of Laravel v5.3.

Install Polymer

cd application/resources
bower init
bower install --save polymer

Include the components in the <head> of application/resources/views/layout.blade.php:

<script src="../bower_components/webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="../bower_components/polymer/polymer.html">

Folders

In /application/resources:

mkdir elements
cd elements
touch elements.html

Include elements.html in the <head> under the previous links:

<link rel="import" href="../elements/elements.html">

Use elements.html to import all your elements from either bower_components or your own custom elements.

Gulp file

Install Vulcanize

cd application
npm install --save-dev gulp-vulcanize

Require vulcanize, copy bower_components and vulcanize elements.html into public:

const elixir = require('laravel-elixir');
const vulcanize = require('gulp-vulcanize');

elixir(mix => {
   mix.sass('app.scss')
   .copy('resources/bower_components', 'public/bower_components')
});


gulp.task('vulcanize', function () {
   return gulp.src('resources/elements/elements.html')
   .pipe(vulcanize({
      stripComments: true,
      inlineCss: true,
      inlineScripts: true
   }))
   .pipe(gulp.dest('public/elements/'));
});

Rendering Polymer in a Blade template

  • Create your Polymer elements in:
application/resources/elements
  • Include your elements in /resources/elements/elements.html:
<link rel="import" href="./polymer-counter.html" />
  • Include the element tag in a blade template:
@extends('layout')
@section('content')
    <polymer-counter></polymer-counter>
@endsection
@remarcable
Copy link

Hey, thank's for this guide. Still, something is not working for me.

First: In the Gulp section it should say:
npm install --save-dev gulp-vulcanize

I get some errors:

elements.html:370 Uncaught DOMException: Failed to execute 'registerElement' on 'Document': Registration failed for type 'dom-module'. A type with that name is already registered.
    at http://coding.dev:8000/elements/elements.html:370:10
    at http://coding.dev:8000/elements/elements.html:385:2
(anonymous) @ elements.html:370
(anonymous) @ elements.html:385
elements.html:78 Uncaught TypeError: Polymer.Base._getExtendedPrototype is not a function
    at desugar (elements.html:78)
    at window.Polymer (elements.html:65)
    at elements.html:7000
    at elements.html:7102
desugar @ elements.html:78
window.Polymer @ elements.html:65
(anonymous) @ elements.html:7000
(anonymous) @ elements.html:7102
elements.html:194 Uncaught TypeError: this._desugarBehaviors is not a function
    at HTMLElement.registerCallback (elements.html:194)
    at desugar (elements.html:81)
    at window.Polymer (elements.html:65)
    at elements.html:8659
registerCallback @ elements.html:194
desugar @ elements.html:81
window.Polymer @ elements.html:65
(anonymous) @ elements.html:8659
elements.html:194 Uncaught TypeError: this._desugarBehaviors is not a function
    at HTMLElement.registerCallback (elements.html:194)
    at desugar (elements.html:81)
    at window.Polymer (elements.html:65)
    at elements.html:9044
registerCallback @ elements.html:194
desugar @ elements.html:81
window.Polymer @ elements.html:65
(anonymous) @ elements.html:9044
elements.html:194 Uncaught TypeError: this._desugarBehaviors is not a function
    at HTMLElement.registerCallback (elements.html:194)
    at desugar (elements.html:81)
    at window.Polymer (elements.html:65)
    at elements.html:9535
registerCallback @ elements.html:194
desugar @ elements.html:81
window.Polymer @ elements.html:65
(anonymous) @ elements.html:9535

Do you have any idea what the problem could be? I startet both the default and the vulcanize task.

@remarcable
Copy link

I further recommend to mention .gitignore :)

@cleopatra27
Copy link

This isn't working...... and when i inspect the page it says 404 for the elements.html and bower scripts in the layout.

@searleb
Copy link
Author

searleb commented Apr 15, 2017

@lightningboss @cleopatra27 Hey, I've only just seen your comments! Did either of you figure it out?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment