[Angular] Use ngx-build-plus to compile Angular Elements
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.
[Angular] Use ngx-build-plus to compile Angular Elements的更多相关文章
- 为什么angular library的build不能将assets静态资源打包进去(转)
Versions Angular CLI: 6.0.7 Node: 9.3.0 OS: darwin x64 Angular: 6.0.3 ... animations, common, compil ...
- [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 ...
- 从Java角度理解Angular之入门篇:npm, yarn, Angular CLI
本系列从Java程序员的角度,带大家理解前端Angular框架. 本文重点介绍Angular的开发.编译工具:npm, yarn, Angular CLI,它们就像Java在中的Maven,同时顺便介 ...
- (转载)从Java角度理解Angular之入门篇:npm, yarn, Angular CLI
本系列从Java程序员的角度,带大家理解前端Angular框架. 本文是入门篇.笔者认为亲自动手写代码做实验,是最有效最扎实的学习途径,而搭建开发环境是学习一门新技术最需要先学会的技能,是入门的前提. ...
- Angular 个人深究(一)【Angular中的Typescript 装饰器】
Angular 个人深究[Angular中的Typescript 装饰器] 最近进入一个新的前端项目,为了能够更好地了解Angular框架,想到要研究底层代码. 注:本人前端小白一枚,文章旨在记录自己 ...
- [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 ...
- angular.module()创建、获取、注册angular中的模块
// 传递参数不止一个,代表新建模块;空数组代表该模块不依赖其他模块 var createModule = angular.module("myModule", []); // 只 ...
- Angular入门,开发环境搭建,使用Angular CLI创建你的第一个Angular项目
前言: 最近一直在使用阿里的NG-ZORRO(Angular组件库)开发公司后端的管理系统,写了一段时间的Angular以后发现对于我们.NET后端开发而言真是非常的友善.因此这篇文章主要是对这段时间 ...
- 使用Angular CLI进行Build (构建) 和 Serve
第一篇文章是: "使用angular cli生成angular5项目" : http://www.cnblogs.com/cgzl/p/8594571.html 第二篇文章是: & ...
随机推荐
- POJ 2987 Firing 网络流 最大权闭合图
http://poj.org/problem?id=2987 https://blog.csdn.net/u014686462/article/details/48533253 给一个闭合图,要求输出 ...
- bzoj 4408: [Fjoi 2016]神秘数 数学 可持久化线段树 主席树
https://www.lydsy.com/JudgeOnline/problem.php?id=4299 一个可重复数字集合S的神秘数定义为最小的不能被S的子集的和表示的正整数.例如S={1,1,1 ...
- Substring with Concatenation of All Words 题解
题意 You are given a string, s, and a list of words, words, that are all of the same length. Find all ...
- 请你谈谈cookie的利弊
以下均是自己理解和整理的,如果有错误请指出,谢谢O(∩_∩)O~~ 优点 极高的扩展性和可用性. 1) 数据持久性. 2) 不需要任何服务器资源.Cookie存储在客户端并在发送后由服务器读取. ...
- python开发_tkinter_菜单的不同选项
python的tkinter模块中,菜单也可以由你自定义你的风格 下面是我做的demo 运行效果: ====================================== 代码部分: ===== ...
- vijos 1659 河蟹王国 线段树区间加、区间查询最大值
河蟹王国 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 https://vijos.org/p/1659 Description 河蟹王国有一位河蟹国王,他 ...
- C# 高级编程9 第30章MEF C#可扩展编程之MEF第2章(抄录)
Managed Extensibility Framework (MEF) 什么是 MEF? Managed Extensibility Framework 即 MEF 是用于创建轻量.可扩展应用 ...
- Ubuntu16.04配置Android5.0编译环境
1.安装jdk7 Ubuntu16.04的安装源已经默认没有openjdk7了,所以要自己手动添加仓库,如下: $ sudo add-apt-repository ppa:openjdk-r/ppa ...
- apache上部署django的静态文件
一直在优化自己博客的代码, 昨天把css样式表分离出来, 用作静态 文件, 但是自己还没学django怎么使用静态文件, 经过一番google 终于解决了. django 使用静态文件有两种方法, 一 ...
- lykchat+zabbix实现微信告警
http://www.ttlsa.com/zabbix/lykchat-zabbix-wechat-alert/