The following walk-through uses angular-cli my-app to quick start a simple usage scenario. Please read through, and adapt for your project's specific needs.
First and foremost, follow the instructions in order to get the angular my-app running locally. https://angular.io/guide/setup-local
npm install -g @angular/cli
ng new my-app
cd my-app
ng serve --open
Add peerDependencies & devDependencies to match the following:
Note: at this point, only version 2.1.5-dev
works for "@momentum-ui/web-components" within an angular application.
"peerDependencies": {
"@momentum-ui/core": "^19.9.12",
"@momentum-ui/icons": "^7.54.0",
"@momentum-ui/tokens": "^1.5.0",
"@momentum-ui/utils": "^6.2.7",
"@momentum-ui/web-components": "2.1.5-dev",
"lit-element": "^2.3.1",
"lit-html": "^1.2.1"
},
and add these to the devDependencies
:
"@momentum-ui/core": "^19.9.12",
"@momentum-ui/icons": "^7.54.0",
"@momentum-ui/tokens": "^1.5.0",
"@momentum-ui/utils": "^6.2.7",
"@momentum-ui/web-components": "2.1.5-dev",
"lit-element": "2.3.1",
"lit-html": "1.2.1",
The changes to scripts commands enable the following Webpack modifications to be run within the Create React App environment.
The addition of jest
as a resolution is important for tests to run
Update the file to match the following (line 1 and line 15 changed):
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule
],
providers: [],
bootstrap: [AppComponent],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
export class AppModule { }
Set esModuleInterop to true under compilerOptions
"compilerOptions": {
"esModuleInterop": true,
- Add the following import:
import '@momentum-ui/web-components';
OR import each individual web component
import '@momentum-ui/web-components/dist/comp/md-button';
import '@momentum-ui/web-components/dist/comp/md-icon';
NOTE: You only need to import the web-components module at the top level of your application in order to use web components anywhere throughout.
- Insert the following sample web component for testing purposes:
<md-theme>
<md-button variant="green"><md-icon slot="icon" name="play_16"></md-icon><span slot="text">Code On!</span></md-button>
</md-theme>
NOTE: You must wrap your application with the <md-theme>
element. It provides a set of core style resets and CSS custom variables that provide Theme color tokens, among other things. You can test these by toggling attributes lumos
and/or darkTheme
on the <md-theme>
element.
(within my-app
directory)
yarn
installs all dependencies.yarn build
copies the required static assets for fonts and icons.yarn start
launches project locally.