$ ng g application create-todo --style=scss --prefix=create --viewEncapsulation=ShadowDom --routing=false
Last active
March 13, 2020 03:16
-
-
Save paul58914080/07dca0d6dde5225bf33c18032581a5a3 to your computer and use it in GitHub Desktop.
create-todo-micro-app
$ ng g module create-todo --flat=true --project=create-todo
$ ng g component create-todo --module=create-todo --selector=create-todo --entryComponent=true --flat=true --project=create-todo
$ ng g service create-todo --flat=true --project=create-todo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {NgModule} from '@angular/core'; | |
import {CommonModule} from '@angular/common'; | |
import {HomeComponent} from './home.component'; | |
import {CreateTodoModule} from '../../../projects/create-todo/src/app/create-todo.module'; | |
@NgModule({ | |
declarations: [ HomeComponent ], | |
imports: [ | |
CommonModule, | |
CreateTodoModule | |
] | |
}) | |
export class HomeModule { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="container-fluid"> | |
<create-todo></create-todo> | |
</div> |
$ ng add @angular/elements --project=create-todo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Injector, NgModule} from '@angular/core'; | |
import {CommonModule} from '@angular/common'; | |
import {CreateTodoComponent} from './create-todo.component'; | |
import {BrowserModule} from '@angular/platform-browser'; | |
import {createCustomElement} from '@angular/elements'; | |
@NgModule({ | |
declarations: [ CreateTodoComponent ], | |
imports: [ | |
CommonModule, | |
BrowserModule | |
], | |
entryComponents: [ CreateTodoComponent ], | |
bootstrap: [ CreateTodoComponent ], | |
exports: [ CreateTodoComponent ] | |
}) | |
export class CreateTodoModule { | |
constructor(private injector: Injector) { | |
} | |
ngDoBootstrap() { | |
const createTodoElement = createCustomElement(CreateTodoComponent, { injector: this.injector }); | |
customElements.define('create-todo-element', createTodoElement); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs-extra'); | |
const concat = require('concat'); | |
const del = require('del'); | |
(async function build() { | |
const files = [ | |
'dist/create-todo/runtime-es2015.js', | |
'dist/create-todo/polyfills-es2015.js', | |
'dist/create-todo/main-es2015.js' | |
]; | |
await del(['dist/elements/create-todo.js']); | |
await fs.ensureDir('dist/elements'); | |
await concat(files, 'dist/elements/create-todo.js'); | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const environment = { | |
production: false, | |
loadBootstrap: true | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const environment = { | |
production: true, | |
loadBootstrap: false | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Injector, NgModule} from '@angular/core'; | |
import {CommonModule} from '@angular/common'; | |
import {CreateTodoComponent} from './create-todo.component'; | |
import {BrowserModule} from '@angular/platform-browser'; | |
import {createCustomElement} from '@angular/elements'; | |
import {environment} from '../environments/environment'; | |
@NgModule({ | |
declarations: [ CreateTodoComponent ], | |
imports: [ | |
CommonModule, | |
BrowserModule | |
], | |
entryComponents: [ CreateTodoComponent ], | |
bootstrap: environment.loadBootstrap? [ CreateTodoComponent ] : [], | |
exports: [ CreateTodoComponent ] | |
}) | |
export class CreateTodoModule { | |
constructor(private injector: Injector) { | |
} | |
ngDoBootstrap() { | |
const createTodoElement = createCustomElement(CreateTodoComponent, { injector: this.injector }); | |
customElements.define('create-todo-element', createTodoElement); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Web component</title> | |
</head> | |
<body> | |
<create-todo-element></create-todo-element> | |
<script type='application/javascript' src='create-todo.js'></script> | |
</body> | |
</html> |
$ npm i --save @angular-builders/custom-webpack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"create-todo": { | |
"projectType": "application", | |
"architect": { | |
"build": { | |
"builder": "@angular-builders/custom-webpack:browser", | |
"options": { | |
"customWebpackConfig": { | |
"path": "projects/create-todo/build/extra-webpack.config.js", | |
"mergeStrategies": { | |
"externals": "replace" | |
} | |
} | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
output: { | |
jsonpFunction: 'webpackJsonpCreateTodo' | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"micro-frontend-todo": { | |
"architect": { | |
"build": { | |
"options": { | |
"scripts": [ | |
{ | |
"input": "node_modules/document-register-element/build/document-register-element.js" | |
}, | |
"dist/elements/create-todo.js" | |
] | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, OnInit } from '@angular/core'; | |
@Component({ | |
selector: 'todo-home', | |
templateUrl: './home.component.html', | |
styleUrls: ['./home.component.scss'] | |
}) | |
export class HomeComponent implements OnInit { | |
loadElement = false; | |
constructor() { } | |
ngOnInit() { | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@import url(‘https://stackpath.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@import url("https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@import url("https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment