and the regexp matches those svg-references (with or without version specification). Depending on your webpack setup you might not need it or you may need something else.
Edit: I'm using angular ^4.0.0 and Electron ^1.4.3
If you have issues with ElectronJS or similar and have a sort of 404 error, a possible workaround is to uedit your webpack.config.js, by adding (and by assuming that you have the font-awesome node module installed through npm or in the package.json file):
new CopyWebpackPlugin([
{ from: 'node_modules/font-awesome/fonts', to: 'assets' },
{ from: 'src/assets', to: 'assets' }
]),
Note that the webpack configuration I'm using has src/app/dist as output, and, in dist, an assets folder is created by webpack:
Webpack is copying the fonts folder to the dev assets folder.
Webpack is copying the dev assets folder to the dist assets folder
Now, when the build process will be finished, the application will need to look for the .scss file and the folder containing the icons, resolving them properly.
To resolve them, I've used this in my webpack config:
// support for fonts
{
test: /\.(ttf|eot|svg|woff(2)?)(\?[a-z0-9=&.]+)?$/,
loader: 'file-loader?name=dist/[name]-[hash].[ext]'
},
Finally, in the .scss file, I'm importing the font-awesome .scss and defining the path of the fonts, which is, again, dist/assets/font-awesome/fonts. The path is dist because in my webpack.config the output.path is set as helpers.root('src/app/dist');
Note that, in this way, it will define the font path (used later in the .scss file) and import the .scss file using ~font-awesome to resolve the font-awesome path in node_modules.
This is quite tricky, but it's the only way I've found to get around the 404 error issue with Electron.js
For webpack2 use:
instead of
file-loader?name=/assets/fonts/[name].[ext]
Using LESS (not SCSS) and Angular 2.4.0 and standard Webpack (not Angular CLI, the following worked for me:
and (in my app.component.less):
and of course you may need this obvious and highly intuitive snippet (in module.loaders in webpack.conf)
The loader is there to fix webpack errors of the kind
and the regexp matches those svg-references (with or without version specification). Depending on your webpack setup you might not need it or you may need something else.
There are 3 parts to using Font-Awesome in Angular Projects
Installation
Install from NPM and save to your package.json
Styling If using CSS
Insert into your style.css
Styling If using SCSS
Insert into your style.scss
Usage with plain Angular 2.4+ 4+
Usage with Angular Material
In your app.module.ts modify the constructor to use the
MdIconRegistry
and add
MatIconModule
to your@NgModule
imports}
Now in any template file you can now do
UPDATE 8 Oct 2019:
You can use a new package https://www.npmjs.com/package/@fortawesome/angular-fontawesome
Add
FontAwesomeModule
to imports insrc/app/app.module.ts
:Tie the icon to the property in your component
src/app/app.component.ts
:Use the icon in the template
src/app/app.component.html
:ORIGINAL ANSWER:
Option 1:
You can use angular-font-awesome npm module
Import the module:
If you're using Angular CLI, add the font-awesome CSS to styles inside the angular-cli.json
NOTE: If using SCSS preprocessor just change the css for scss
Example Use:
Optoin 2:
There is an official story for that now
Install the font-awesome library and add the dependency to
package.json
npm install --save font-awesome
Using CSS
To add Font Awesome CSS icons to your app...
Using SASS
Create an empty file
_variables.scss
insrc/
.Add the following to
_variables.scss
:$fa-font-path : '../node_modules/font-awesome/fonts';
Instyles.scss
add the following:Test
Run ng serve to run your application in develop mode, and navigate to http://localhost:4200.
To verify Font Awesome has been set up correctly, change
src/app/app.component.html
to the following...After saving this file, return to the browser to see the Font Awesome icon next to the app title.
Also there is a related question Angular CLI outputs the font-awesome font files the dist root as by default angular cli outputs the fonts in to the
dist
root, which is by the way not an issue at all.After some experimentation I managed to get the following working:
Install with npm:
add to angular-cli-build.js file:
add to index.html
The key was to include the font file types in the angular-cli-build.js file
.+(css|css.map|otf|eot|svg|ttf|woff|woff2)
Edit: I'm using angular ^4.0.0 and Electron ^1.4.3
If you have issues with ElectronJS or similar and have a sort of 404 error, a possible workaround is to uedit your
webpack.config.js
, by adding (and by assuming that you have the font-awesome node module installed through npm or in the package.json file):Note that the webpack configuration I'm using has
src/app/dist
as output, and, in dist, anassets
folder is created by webpack:So basically, what is currently happening is:
dist
assets folderNow, when the build process will be finished, the application will need to look for the
.scss
file and the folder containing the icons, resolving them properly. To resolve them, I've used this in my webpack config:Finally, in the
.scss
file, I'm importing the font-awesome .scss and defining the path of the fonts, which is, again,dist/assets/font-awesome/fonts
. The path isdist
because in my webpack.config the output.path is set ashelpers.root('src/app/dist');
So, in
app.scss
:Note that, in this way, it will define the font path (used later in the .scss file) and import the .scss file using
~font-awesome
to resolve the font-awesome path innode_modules
.This is quite tricky, but it's the only way I've found to get around the 404 error issue with Electron.js