Last active
July 22, 2019 10:22
-
-
Save paul58914080/38785aaa19cac0021a0ac9bdaa79d100 to your computer and use it in GitHub Desktop.
micro-frontend-codejam-create
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
ng g application create-todo --style=scss --prefix=create --viewEncapsulation=ShadowDom | |
# navigate to projects/create-todo/app | |
ng g module create-todo --flat=true | |
ng g component create-todo --module=create-todo --selector=create-todo --entryComponent=true --flat=true | |
ng g service create-todo --flat=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
@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> | |
<view-todo></view-todo> | |
</div> |
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
# make it a web component | |
@NgModule({ | |
declarations: [ CreateTodoComponent ], | |
providers: [ CreateTodoService ], | |
exports: [ CreateTodoComponent ], | |
imports: [ CommonModule, BrowserModule, FormsModule, HttpClientModule ], | |
entryComponents: [ CreateTodoComponent ], | |
bootstrap: [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/*.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
"build:create-todo:elements": "ng build create-todo --prod --output-hashing none && node projects/create-todo/build/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
"micro-frontend-todo": { | |
"architect": { | |
"build": { | |
"options": { | |
"scripts": [ | |
"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
<div class="todo-create-container"> | |
<create-todo-element></create-todo-element> | |
<create-todo></create-todo> | |
</div> |
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
@NgModule({ | |
declarations: [HomeComponent], | |
imports: [CommonModule, CreateTodoAppModule], | |
bootstrap: [HomeComponent], | |
entryComponents: [HomeComponent], | |
schemas: [CUSTOM_ELEMENTS_SCHEMA] | |
}) | |
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
"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', | |
library: 'createTodo' | |
} | |
}; |
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
<!-- Feature toggle --> | |
<div class="container-fluid" style="width:100%"> | |
<div *ngIf="!loadElements"> | |
<create-todo></create-todo> | |
</div> | |
<div *ngIf="loadElements"> | |
<create-todo-element></create-todo-element> | |
</div> | |
</div> |
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'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment