[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 第二篇文章是: & ...
随机推荐
- Windows下修改Git bash的HOME路径
Windows中使用http://git-scm.com/安装Git bash工具,默认的HOME和~路径一般都是C:\Users\用户名,每次得用命令切换到常用的Repository下,此操作重复而 ...
- .vs目录有什么用?
写这篇博文的目的就是方便后来者能够在百度里轻松搜到. 反正我找了半天没找到关于.vs目录的介绍,最后还是在同事的帮助下才找到的. 参考地址:https://developercommunity.vis ...
- 使用Django来处理对于静态文件的请求
引言 本方法适用于linux+python2.7+django1.2,使用django自带的web服务. 同样也适用于sina app engine. 1.准备工作 准备css文件,准备js文件,准备 ...
- 【Go入门教程9】并发(goroutine,channels,Buffered Channels,Range和Close,Select,超时,runtime goroutine)
有人把Go比作21世纪的C语言,第一是因为Go语言设计简单,第二,21世纪最重要的就是并行程序设计,而Go从语言层面就支持了并行. goroutine goroutine是Go并行设计的核心.goro ...
- MFC小程序------01 代码管理器
1.代码入库: 2.代码查找: 3.查看全部代码: 4.程序设置: 自己学习MFC写的一个小程序,当中还有很多功能还待完好,比方数据库的导入功能还没有写,但导出功能是能够用的,查找算法也不是非常好,还 ...
- MapReduce实现排序功能
期间遇到了无法转value的值为int型,我採用try catch解决 str2 2 str1 1 str3 3 str1 4 str4 7 str2 5 str3 9 用的\t隔开,得到结果 str ...
- MFC中添加ToolTip提示框
PART 1 MFC 对话框中的 Buttton添加提示 例如我们想在一个对话框中的一个button控件添加tooltip,实现的方法如下: 1. 在该对话框的类中添加一个CToolTipCtrl类型 ...
- UI----------------Toggle
Is On:是否已经勾选上了 Toggle Transition:渐变效果 Graphic:勾选标志的图,就是那个勾 Group:多选组 On Value Changed:当选项改变时,触发事件 多选 ...
- putty的保存功能如何使用
Putty的设置保存功能隐藏的实在太好了,原来在Connection菜单中修改设置后,并不能在该界面保存. 保存步骤: 1.需要点击Session菜单,选中下面的Default Setting. 2. ...
- C预编译, 预处理, C/C++头文件, 编译控制,
在所有的预处理指令中,#Pragma 指令可能是最复杂的了,它的作用是设定编译器的状态或者是指示编译器完成一些特定的动作.#pragma指令对每个编译器给出了一个方法,在保持与C和C++语言完全兼容的 ...