qdouble / angular-webpack-starter

A complete Angular 6 and Webpack 4 starter seed with minimal and full featured branches. Full featured branch includes: Material Design 2 (Bootstrap 4 branch available as well), @ngrx, HMR, DLLs and optional use of Universal for server-side rendering - Supports AOT (offline) compilation, sync and lazy loading. Karma/Protractor for e2e/unit tests.
MIT License
883 stars 181 forks source link

How to add fonts #318

Open jeusdi opened 6 years ago

jeusdi commented 6 years ago

I've installed font-awesome:

npm install font-awesome

I've added these rules on constants.js:

exports.MY_CLIENT_RULES = [
  // use this to import your own rules for Client webpack config.
  { test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: "url-loader?limit=10000&mimetype=application/font-woff" },
  { test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: "file-loader" }
]

Into my styles.scss I've added this import:

@import "font-awesome/scss/font-awesome.scss";

font-awesome css rules are loaded but, fonts are not loaded.

It seems fonts are requested by browser:

enter image description here

However, the response is the main html page:

enter image description here

Any ideas?

jeusdi commented 6 years ago

Any ideas?

Zwimber commented 6 years ago

The most likely reason is that the path is not entirely correct but I would need more information to exactly pinpoint the problem. I would recommend just using a CDN for now.

Good luck!

leqwasd commented 6 years ago

I think I got it working. In webpack.config.ts

{ test: /.scss$/, loaders: ['to-string-loader', 'css-loader', 'resolve-url-loader', 'sass-loader?sourceMap'] }, { test: /.woff(2)?(\?v=[0-9].[0-9].[0-9])?$/, loader: "url-loader?limit=10000&minetype=application/font-woff"}, { test: /.(png|jpg|jpeg|gif|svg)$/, loader: "url-loader?limit=10000" }, { test: /.(ttf|eot|svg)(\?v=[0-9].[0-9].[0-9])?$/, loader: "file-loader" },

And in my .scss file I just

@import '~font-awesome/scss/font-awesome.scss'

I am super new to this specific Angular file handling proccess. This was cobbled together from examples all around the web.