How to build webcomponentjs v0 polyfill and include in angular

Reading Time: < 1 minutes

 84 total views

1) git clone repository
2) check out v0 branch
3) install gulp globally

npm install -g gulp

4) build webcomponentjs manually

 npm install
 gulp build

5) Find the generate js files in dist/ folder
6) Copy webcomponents.min.js to assets folder of angular project
7) import webcomponents.min.js to polyfill.ts

import "./assets/webcomponents.min";

Create custom element in angular 6

Reading Time: 2 minutes

 84 total views

1) Create Angular Project

ng new <project name> --prefix custom --style=scss --skip-tests

2) Use schematics to add angular element support

ng add @angular/elements

3) Use angular-cli to generate new component and specify encapsulation is ViewEncapsulation.Native

4) REmove the document-create-element polyfill from script array.

5) Install custom-lements polyfill, “@webcomponents/custom-elements”

yarn add @webcomponents/custom-elements

6) Update polyfills.ts to include native-shim polyfill

// Shim for Browsers supporting Custom Elements
// Needed b/c Custom Elements ist defined for ES6+
// while we are downleveling to ES5.
import "@webcomponents/custom-elements/src/native-shim.js";

7) Include custom elements in entryComponents array of module

  imports: [CommonModule, HttpClientModule, FormsModule, NgbModule],
  declarations: [
  entryComponents: [InputTimeFormComponent, InputThemeComponent],
  exports: [InputTimeFormComponent, InputThemeComponent]
export class TimeZoneModule {}

8) Assume the custom element uses Bootstrap 4 for styling. Then, import Bootstrap Sass in scss file of the component.

$icon-font-path: "../../../../node_modules/bootstrap-sass/assets/fonts/bootstrap/";
@import "~bootstrap/scss/bootstrap";

6) AppModule does not bootstrap or declare AppComponent. It also defines ngDoBoostrap function to register custom elements in custom element registry. createCustomElement creates custom element class based on Angular Component and define function of customElements registers the new custom element class.

import { BrowserModule } from "@angular/platform-browser";
import { NgModule, Injector } from "@angular/core";
import { FormsModule } from "@angular/forms";
import { HttpClientModule } from "@angular/common/http";
import { createCustomElement } from "@angular/elements";

import { NgbModule } from "@ng-bootstrap/ng-bootstrap";
import {
} from "./time-zone/";

  imports: [
export class AppModule {
  constructor(private injector: Injector) {}

  ngDoBootstrap() {
    console.log("AppModule ngDoBootstrap");
    const timeConverterElement = createCustomElement(InputTimeFormComponent, {
      injector: this.injector
    const timeThemeElement = createCustomElement(InputThemeComponent, {
      injector: this.injector
    customElements.define("time-converter", timeConverterElement);
    customElements.define("time-theme", timeThemeElement);

9) After AppModule is bootstrapped in main.ts, optionally assigns value to attribute of custom element

  .then(() => {
    const color = 'goldenrod';
    const themeChooser = document.getElementsByTagName("time-theme")[0];
    themeChooser.setAttribute("theme", color);

    const converter = document.getElementsByTagName("time-converter")[0];
    converter.setAttribute("theme", color);
  .catch(err => console.log(err));

8) Build a nodeJS script to concatenate runtime.js, polyfill.js, script.js, main.js into time-converter.js. The time-converter.js can be used in other JS Frameworks and static website.

const fs = require("fs-extra");
const concat = require("concat");
(async function build() {
  const files = [
  await fs.ensureDir("elements");
  await fs.emptyDir("elements");
  await concat(files, "elements/time-converter.js");
  await fs.copyFile(
  await fs.copy("./dist/ng-time-converter/assets/", "elements/assets/");
  await fs.copyFile("./src/demo.html", "elements/index.html");
  await fs.copyFile("CNAME", "elements/CNAME");

Articles I want to read

Reading Time: < 1 minutes

 96 total views,  2 views today





React Native

codebuddies contributions (As of May 24, 2018)

Reading Time: < 1 minutes

 98 total views,  2 views today

Make 3 Pull Requests to repo

  1. Join study group prompt login
  2. #830 Add global activity feed on home logged out page
  3. #871 Send notification to Facebook and Slack when hangout time has been changed.

codebuddies 1.1 release.

Import bootstrap-sass in vuejs

Reading Time: < 1 minutes

 90 total views

1) yarn add bootstrap bootstrap-sass node-sass sass-loader

yarn add boostrap bootstrap-sass node-sass sass-loader

2) Set $icon-font-path to find font files and import variable.scss and _bootstrap.scss

$icon-font-path: "~bootstrap-sass/assets/fonts/bootstrap/";
@import "~bootstrap-sass/assets/stylesheets/bootstrap/variables";
@import "~bootstrap-sass/assets/stylesheets/_bootstrap.scss";

3) In main.js, require(‘./assets/sass/main.scss’);
4) type yarn serve to launch application in development mode. Index page should open at url http://localhost:8080.

yarn serve

// add any variables you want to override here
// ———
// ———
$icon-font-path: ‘~bootstrap-sass/assets/fonts/bootstrap/’;
@import ‘~bootstrap-sass/assets/stylesheets/bootstrap’;

Projects built in May, 2018

Reading Time: < 1 minutes

 96 total views


CSS Grid


codebuddies contributions (As of May 3, 2018)

Reading Time: < 1 minutes

 94 total views

Make 5 Pull Requests to repo

  1. Opt out of auto-tweeted learnings – You can now opt out of auto-tweeting your learnings when you share a learning
  2. Github signin link added to the home page
  3. Bug fix: owner of completed hangout can create a hangout from the same page (broken button)
  4. Bug fix: hide google calendar button in completed hangout
  5. Remove duplicated code in the Meteor.LoginWithSlack function

codebuddies 1.0 release.