-
Notifications
You must be signed in to change notification settings - Fork 25
HelixUI with Angular
NOTE: I'm not familiar enough with the "correct" way to bring in 3rd party, static assets, so this guide may not contain the best solution, but id does provide a solution.
- Latest stable NodeJS (for the
npm
andnpx
command-line utilities) -
helix-ui
v0.18.0 or later
(all paths are relative to the root of the project directory)
- Your app was bootstrapped via
@angular/cli
- Vendor assets live in
src/assets/vendor/
(coded by 3rd party)
npm install helix-ui
npm install --save-dev vendor-copy
-
vendor-copy
allows you to automatically copy bundled assets to your project afternpm install
.
Include the following configurations:
{
"scripts": {
"postinstall": "vendor-copy"
},
"devVendorCopy": [
{
"from": "node_modules/helix-ui/node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js",
"to": "src/assets/vendor/webcomponents-loader.js"
},
{
"from": "node_modules/helix-ui/node_modules/@webcomponents/webcomponentsjs/bundles",
"to": "src/assets/vendor/bundles"
},
{
"from": "node_modules/helix-ui/dist/css/helix-ui.min.css",
"to": "src/assets/vendor/helix-ui.min.css"
}
]
}
Run the following to copy files configured via the vendorCopy
configuration, above.
npx vendor-copy
NOTE: You may also want to verify that your postinstall
script is working as expected, by running npm install
.
Add the following to the bottom of the <head>
element:
<link rel="stylesheet" href="assets/vendor/helix-ui.min.css">
<!-- Required for HelixUI to function in older browsers -->
<script src="assets/vendor/webcomponents-loader.js"></script>
Import HelixUI
import HelixUI from 'helix-ui';
Then, change the following:
platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => console.error(err));
to this:
HelixUI.initialize()
.then(() => platformBrowserDynamic().bootstrapModule(AppModule))
.catch(err => console.error(err));
By default, Angular doesn't configure your app to support custom elements and you'll see an error similar to the following.
To correct this issue, add CUSTOM_ELEMENTS_SCHEMA
to the list of schemas in src/app/app.module.ts
(configures angular to allow 3rd-party custom elements).
import { BrowserModule } from '@angular/platform-browser';
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule
],
providers: [],
bootstrap: [AppComponent],
schemas: [ CUSTOM_ELEMENTS_SCHEMA ]
})
export class AppModule { }
TBD...