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?
Funny I was trying to get the same thing working this morning. This is all I had to do in my aurelia.json dependencies for it to work:
Then in my html I had:
importing css/fonts automagicly is now supported.
Checkout this "Issue" https://github.com/aurelia/cli/issues/249
Happy codding
EDIT
I realized/read the comments this does not copy the font files. Here is an updated build script (es6) that will copy any resources and add the folder to the git ignore. If you want the typescript version check here
https://github.com/aurelia/cli/issues/248#issuecomment-253837412
./aurelia_project/tasks/build.js
For those who wish to use the sass version of font-awesome
1) Install font-awesome
2) Copy font-awesome's fonts to your project root directory
3) Include the font-awesome sass directory in the aurelia css processor task
4) Import font-awesome in your app scss
5) Require your app scss in your html
You don't need more much this:
in aurelia.json
See section Setup for copying files
i hope help you.
Don't add font-awesome resources to aurelia.json - you'd need font files too, which Aurelia don't process. Instead, take the following steps.
First, if you added anything for font-awesome already to your
aurelia.json
file, remove it again.Add new file
prepare-font-awesome.js
in folder\aurelia_project\tasks
and insert the below code. It copies font-awesome resource files to output folder (as configuredaurelia.json
config file; e.g.scripts
):Open the
build.js
file in the\aurelia_project\tasks
folder and insert the following two lines; this will import the new function and execute it:Finally, in the
<head>
section of yourindex.html
file, just add the following line:That's all; now you can use font-awesome icons in any Aurelia view modules (html files).
Note that this works for any complex third party library which requires resources which you have to manually include.
Not actually answering to your question of how to integrate Font Awesome in your application using NPM, but there is an alternative, clean way to get it in your application: using the CDN.
As mentioned in other answers, Aurlia currently doesn't support bundling resources other than js, css and html out-of-the-box using the CLI. There's a lot of discussion about this subject, and there are several, mostly hacky, workarounds, like some suggested here.
Rob Eisenberg says he's planning on getting it properly integrated in the Aurelia CLI, but he considers it low priority because there's a simple workaround. To quote him:
<require>
tags,...