We can treat Angular Element as each standlone lib and compile each Angular element spreatly. Tool we are using to compile Angular element is 'ngx-build-plus':

Install:

npm i --save ngx-build-plus

It modifies the angular.json to use ngx-build-plus to compile our Angular Element lib.

Generate a project with Angular CLI and only keep the app.module.ts and your component ts file:

// app.module.ts:

import { NgModule, Injector } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { createCustomElement } from '@angular/elements'; import { GreeterComponent } from './greeter.component'; @NgModule({
declarations: [GreeterComponent],
imports: [BrowserModule],
providers: [],
entryComponents: [GreeterComponent]
})
export class AppModule {
constructor(injector: Injector) {
const el = createCustomElement(GreeterComponent, { injector: injector });
customElements.define('do-greet', el);
} ngDoBootstrap() {}
}

component.ts:

import { Component, OnInit } from '@angular/core';

@Component({
// selector: 'do-greet',
template: `
<div>
Hi there!
</div>
`,
styles: []
})
export class GreeterComponent implements OnInit {
constructor() {} ngOnInit() {}
}

Create a buildEl.sh file for build Angular Elemenet:

#!/bin/sh
ng build ngelements --prod --output-hashing=none --single-bundle true --keep-polyfills true
mv dist/ngelements/main.js demo/ngelements.js
mv dist/ngelements/polyfills.js demo

The build script will:

  • output two files: main.js and polyfill.js. main.js contains Angular elemenet, polyfill is mainly used for testing demo app, normally production app has polyfill already. So we don't need to include ployfill inside main.js
  • output files locates in 'dist' folder under root.
  • We copy main.js and polyfill.js to demo folder for testing our Angular elements and rename main,js to ngelement.js.

Github, More

[Angular] Use ngx-build-plus to compile Angular Elements的更多相关文章

  1. 为什么angular library的build不能将assets静态资源打包进去(转)

    Versions Angular CLI: 6.0.7 Node: 9.3.0 OS: darwin x64 Angular: 6.0.3 ... animations, common, compil ...

  2. [Angular2 Form] Build Select Dropdowns for Angular 2 Forms

    Select Dropdowns in Angular 2 a built with select and option elements. You use *ngFor to loop throug ...

  3. 从Java角度理解Angular之入门篇:npm, yarn, Angular CLI

    本系列从Java程序员的角度,带大家理解前端Angular框架. 本文重点介绍Angular的开发.编译工具:npm, yarn, Angular CLI,它们就像Java在中的Maven,同时顺便介 ...

  4. (转载)从Java角度理解Angular之入门篇:npm, yarn, Angular CLI

    本系列从Java程序员的角度,带大家理解前端Angular框架. 本文是入门篇.笔者认为亲自动手写代码做实验,是最有效最扎实的学习途径,而搭建开发环境是学习一门新技术最需要先学会的技能,是入门的前提. ...

  5. Angular 个人深究(一)【Angular中的Typescript 装饰器】

    Angular 个人深究[Angular中的Typescript 装饰器] 最近进入一个新的前端项目,为了能够更好地了解Angular框架,想到要研究底层代码. 注:本人前端小白一枚,文章旨在记录自己 ...

  6. [Angular 8] Take away: Web Components with Angular Elements: Beyond the Basics

    This post is based on the NG-CONF talk, check the talk by yourself. 1. Dynamiclly add Angular Elemen ...

  7. angular.module()创建、获取、注册angular中的模块

    // 传递参数不止一个,代表新建模块;空数组代表该模块不依赖其他模块 var createModule = angular.module("myModule", []); // 只 ...

  8. Angular入门,开发环境搭建,使用Angular CLI创建你的第一个Angular项目

    前言: 最近一直在使用阿里的NG-ZORRO(Angular组件库)开发公司后端的管理系统,写了一段时间的Angular以后发现对于我们.NET后端开发而言真是非常的友善.因此这篇文章主要是对这段时间 ...

  9. 使用Angular CLI进行Build (构建) 和 Serve

    第一篇文章是: "使用angular cli生成angular5项目" : http://www.cnblogs.com/cgzl/p/8594571.html 第二篇文章是: & ...

随机推荐

  1. 汉化 的 空指针 bug

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha nulljava.lang.NullPointerException at com.an ...

  2. blog搬家啦

    本blog大概不会更新了 新blog地址:https://zykykyk.github.io/

  3. 程序逻辑问题---Writeup

    原题地址:http://ctf5.shiyanbar.com/web/5/index.php 打开后是一处登陆界面 右键查看源代码 发现有一处txt文件 很明显就是程序的源代码 可以看到其中一句 $s ...

  4. [UVa10296]Jogging Trails

    题目大意: 中国邮递员问题. 给你一个无向带权连通图,求经过所有边并返回起点的最短路径. 思路: Edmonds-Johnson算法. 显然,当原图为欧拉图时,答案即为其欧拉回路的长度. 考虑原图不存 ...

  5. Go Web编程 第四章--处理请求

    请求和响应 Request结构 URL字段 Header字段 Body字段 Form, PostForm, MultipartForm字段 在处理器函数中,我们可以通过Request获取各个字段的详细 ...

  6. JAVA基础(一) ——— static 关键字

    1.  静态代码块 保证只创建一次,提升属性的级别为类变量.初始化后独自占用一块内存 2.  静态代码块执行触发条件 (1).当创建这个类的实例 (2).当调用这个类的静态变量 (3).当调用这个类的 ...

  7. bzoj 3262

    题意:给你一些三维上的点,对于每个点,统计三个坐标都小于等于该点的点数. 如果点的范围在300以内,可以用三维树状数组搞,但这题坐标范围太大. 考虑将所有点按照x坐标排序,从左到右,相当于在一个二维平 ...

  8. URAL 1881 Long problem statement

    1881. Long problem statement Time limit: 0.5 secondMemory limit: 64 MB While Fedya was writing the s ...

  9. A SCSI command code -- SIMPLIFIED DIRECT-ACCESS DEVICE (RBC)

    SIMPLIFIED DIRECT-ACCESS DEVICE (RBC) ------------------------------------------ OP B Description -- ...

  10. 斑马Zebra驱动下载

    Zebra GT800 点击进入下载页-> 自动安装包[WINXP/WIN7/WIN8]点击进入下载页-> 添加打印机向导[WINXP/WIN7/WIN8]   热门下载 · Zebra ...