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. android 安全退出 activity

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha 定义一个 活动 的基础类, 每次打开一个 活动,就记录下来. 退出时,关闭每一个 活动. ...

  2. QT学习笔记7:C++函数默认参数

    C++中允许为函数提供默认参数,又名缺省参数. 使用默认参数时的注意事项: ① 有函数声明(原型)时,默认参数可以放在函数声明或者定义中,但只能放在二者之一.建议放在函数声明中. double sqr ...

  3. luoguP4336 [SHOI2016]黑暗前的幻想乡 容斥原理 + 矩阵树定理

    自然地想到容斥原理 然后套个矩阵树就行了 求行列式的时候只有换行要改变符号啊QAQ 复杂度为\(O(2^n * n^3)\) #include <cstdio> #include < ...

  4. Java并发(二十一):线程池实现原理

    一.总览 线程池类ThreadPoolExecutor的相关类需要先了解: (图片来自:https://javadoop.com/post/java-thread-pool#%E6%80%BB%E8% ...

  5. Atlas 安装运行随笔

    Atlas 是一个用于数据库负载均衡 ,读写分离的中间件,他实现了mysql 的语法,对于普通调用DAL 层来说的话,和mysql 是一样的. 一,安装1,从源码安装 , 可以参考 http://bl ...

  6. Linux下访问window挂载的磁盘

    点击window挂在的磁盘,如下图左侧"文档". 出现如下错误: Error mounting /dev/sda3 .... Command-line `mount -t &quo ...

  7. oracle开发学习篇之集合函数

    集合函数; declare type list_nested ) not null; v_all list_nested := list_nested('changan','hubei','shang ...

  8. Git_使用GitHub

    我们一直用GitHub作为免费的远程仓库,如果是个人的开源项目,放到GitHub上是完全没有问题的.其实GitHub还是一个开源协作社区,通过GitHub,既可以让别人参与你的开源项目,也可以参与别人 ...

  9. 小程序swiper 快速滑动闪屏

    bindchange: function(e){ if(e.detail.source == "touch") { this.setData({ current: current ...

  10. phpcms功能列表

    上1 站点首页 就是前台首页 会员中心 跳到会员中心页面 搜索 新闻,图片等文档搜索 锁屏 锁住账号 Phpcms 官网 授权 官网查询 支持论坛 官网论坛 帮助 官网帮助 上2 我的面板 个人信息 ...