I have been following the Contact Manager tutorial and would like to add Font Awesome to the project. Here's what I have done so far:
npm install Font-Awesome --save
- Added the following to
aurelia.json
under the dependencies array of thevendor-bundle.js
:
...
{
"name": "font-awesome",
"path": "../node_modules/font-awesome",
"resources": [
"css/font-awesome.min.css"
]
},
...
But when running au run --watch
I get the error:
error C:\Users\node_modules\font-awesome.js
Why is it looking for the .js file?
Simple default settings method
Here are the 4 simple steps I use to bring in Font-Awesome to an Aurelia project that uses the CLI.
1) npm install font-awesome --save
2) add copyFiles to build of aurelia.json
3) add bundling to dependencies array of aurelia.json
4) include the import for the css file (mine lives in the app.html)
=========================================================================
Alternative
Specifying a custom font location
As I was serving my files from a different location I needed to be able to tweek the font location configured. As such, below are the steps involved if you need to do the same and specify where the fonts are stored. I am using .less
1, 2) As above.
3) Instead of adding to the bundling, you need to reference the font-awesome less file within your own less file (mine is called site.less) and then set the
@fa-font-path
to your custom location.4) There is no 4, with this method as long as you have your own compiled equivalent
site.css
file referenced already (with the import) you don't need to add anything else.I believe that
bundles.dependencies
section is for referencing JS libraries.In your case, a bit of additional work will be needed. According to Aurelia CLI docs, you can create your own generators as well, which comes in handy for us.
Add some new paths to
aurelia.json
:Create a task for css bundling...
au generate task fa-css
Modified task file:
aurelia_project\tasks\fa-css.js|ts
...and another for copying font files:
au generate task fa-fonts
Modified task file:
aurelia_project\tasks\fa-fonts.js|ts
Add these new tasks above to the build process in
aurelia_project\tasks\build.js|ts
:After doing these steps,
au build
should embedfont-awesome.min.css
into scripts/app-bundle.js and copy necessary font files to ./fonts folder.Last thing to do is to require font-awesome within our html.