Replacing external css library file with a locally-stored version - css

I have a css library that I import directly in my main css file like this :
#import url(https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.8.2/css/all.min.css);
I want to store it locally in my project and import it from its folder
I have tried downloading the file and storing it in my assets/css/ directory then adding the path in angular.json like this:
"styles": [
"src/styles.css",
"src/assets/css/all.min.css"
],
But after ng build (it prints all the css file then clear the terminal then no error) then I launch ng serve but I get Failed to compile
How to do this the most clean way? (without installing unneeded files)

If you're trying to download just the all.min.css, it won't work. The font-awesome css package you were importing directly, makes reference to/ depends on other online packages (e.g. sprites and webfonts). My solution would be to use an npm package of font-awesome, or get it from github.
Copied from the all.css:
.fab {
src: url("../webfonts/fa-regular-400.eot");
src: url("../webfonts/fa-regular-400.eot?#iefix") format("embedded-opentype"), url("../webfonts/fa-regular-400.woff2") format("woff2"), url("../webfonts/fa-regular-400.woff") format("woff"), url("../webfonts/fa-regular-400.ttf") format("truetype"), url("../webfonts/fa-regular-400.svg#fontawesome") format("svg"); }

Related

Java/Gradle: Copy folder from external .jar dependency to own build resource folder

Background
I have MaterialFX as an external dependency for my JavaFx project. The project tries to recreate the demo shown in the MaterialFX project. My project uses Gradle (build script in Kotlin).
The demo uses custom fonts provided in its resource path in a javaFxStylesheet.css file to style e.g. the JavaFX Labels:
/*javaFxStylesheet.css*/
#import '../fonts/Fonts.css';
.header {
-fx-font-family: <fontname>`
}
where Fonts.css has multiple entries like
/*Fonts.css*/
#font-face {
font-family: 'Comfortaa SemiBold';
font-weight: 600px;
font-style: normal;
font-display: swap;
src: url('../fonts/Comfortaa/Comfortaa-SemiBold.ttf') format('truetype');
}
Problem
The MaterialFX dependency I pull into my project has the used fonts in a separate folder but how to I use them in my project. As is visible from the demo Fonts.css (which I would like to simply copy into my project), the paths to the fonts e.g. url('../fonts/Comfortaa/Comfortaa-SemiBold.ttf') are specified relative the resources path.
Now, if I want to use the same fonts in my project without changing all the paths, I guess I need to
Copy the fonts-Folder manually from the externally pulled materialfx.jar into my own project resources
Have Gradle automatically do this
So I imagine I need something like the following in my build.gradle:
copy from external library 'materialfx-11.13.9.jar' the folder 'io/github/palexdev/materialfx/font'
into my own projects "src/main/resources"
Note - there seems to be a smiliar issue but I can't make it work as I have no clue if it even aims at the same thing I'm trying to acchieve.

Roots Sage - Bud build doesn't load custom fonts, and shows resolve-url-loader warning

I built a project on the latest Roots/Sage 10.
I didn't modify the bud.config.js and kept it as I cloned from the sage master branch.
Now I am trying to add a custom font by adding this to the app.css:
#font-face {
font-family: "iconfont";
src: url("../fonts/iconfont.ttf?yh9ob") format("truetype"),
url("../fonts/iconfont.woff?yh9ob") format("woff"),
url("../fonts/iconfont.svg?yh9ob#baltimore") format("svg");
font-weight: normal;
font-style: normal;
font-display: block;
}
And I added the font files to the resources/fonts folder.
Folder structure:
- resources
|- fonts
|---- iconfont.svg
|---- iconfont.ttf
|---- iconfont.woff
|- images
|- scripts
|- styles
|---- app.css
...
When I run npm run build, it generates the assets files.
But the font files are not loading on the site.
And when I check the compiled app.[hash].css in the public folder, I can't find anything similar to #font-face....
And I see this at the end of the bud build log:
⚠ Module Warning (from ./node_modules/resolve-url-loader/index.js):
resolve-url-loader: webpack misconfiguration
webpack or the upstream loader did not supply a source-map
⚠ Module Warning (from ./node_modules/resolve-url-loader/index.js):
resolve-url-loader: webpack misconfiguration
webpack or the upstream loader did not supply a source-map
When I run npm run dev, it shows the same message, and just hangs there. The assets are even not generated in the public folder other than manifest.json.
% npm run dev
> dev
> bud dev
⚠ Module Warning (from ./node_modules/resolve-url-loader/index.js):
resolve-url-loader: webpack misconfiguration
webpack or the upstream loader did not supply a source-map
⚠ Module Warning (from ./node_modules/resolve-url-loader/index.js):
resolve-url-loader: webpack misconfiguration
webpack or the upstream loader did not supply a source-map
Again, I didn't configure anything on my own and I only have what I pulled from the sage repo's latest commit.
It's a bit frustrating that the sage default setup is not handling this simple style addition.
Does anyone know if I have to configure anything for the custom font definition?
Currently, the root/sage10 documentation is very thin and I can't seek what I need.
Looking for help!
Thanks in advance...
Issue was solved in the Bud 5.1.0.
See this commit https://github.com/roots/sage/commit/c03663602280a5e5bb9caa5c1c4c4b37a40c7395
Use ~#fonts.
Example:
src: url(~#fonts/iconfont.ttf?yh9ob) format('truetype')

How To Load Fonts In Django

I have a project I am working on in django and i am trying to load locally installed fonts with the .tff extensions but they dont seem to be working. My css code is
#font-face {
font-family: 'JandaAppleCobbler';
src: url('../fonts/JandaAppleCobbler.tff') format("truetype"), local('JandaAppleCobbler');
}
My directory structure is
--static
|--css
| |--main.css
|
|--fonts
|--JandaAppleCobbler.tff

components-font-awesome and angularjs local testing

I am trying (in vain) to get fonts working locally.
I have installed https://github.com/components/font-awesome and there is a line at the bottom of the page that states:
Here is the important part, the default font folder is on different path with the compiled bower file. We need to move the font from default font folder to the compiled bower folder (In the example vendor is the compiled folder).
Now I am using grunt, not gulp and I am also using the sass.
So, in my sass I have done this:
#import "../../bower_components/components-font-awesome/scss/fa-brands";
#import "../../bower_components/components-font-awesome/scss/fa-regular";
#import "../../bower_components/components-font-awesome/scss/fontawesome";
Which pulls in the correct fa fonts, etc.
Then following that text above I created a rule in my gruntfile that does this:
fonts: {
expand: true,
cwd: 'bower_components/components-font-awesome/webfonts/',
src: '*',
dest: '<%= yeoman.app %>/fonts'
}
But when I try to load my site using grunt serve -o I get this message:
Failed to decode downloaded font: http://localhost:9000/webfonts/fa-regular-400.woff2
So I can see it is looking in a different directory, so first of all I just added this to my sass:
$fa-font-path: "/fonts";
But that didn't work either.
So then I decided to change the copy rule to actually copy to /webfonts and still no icons were downloaded.
I have read some posts (with people with similar issues) and they have said the path was relative.
So I decided to copy the fonts and directories to everywhere they might need to be:
/webfonts
/assets/webfonts
/styles/webfonts
/fonts
Even doing that, no fonts are loaded.
Surely someone knows how to fix this?

Rails - using vendor fonts in vendor css in Rails 4 app - asset pipeline

I'm trying to figure out how to adapt a wrap bootstrap theme for use in Rails 4.
The theme uses simple-line-icons. I've tried to move those files to a font folder in my app/assets folder as well as to the css file in my vendor/assets/css folder and the js folder in my vendor/assets/javascript folder.
I don't understand how to rewrite paths in the css so as to reference the assets in a way that will get rails to read them.
For example, one of the css files includes the following:
#font-face {
font-family: 'Simple-Line-Icons';
src: url("../../fonts/Simple-Line-Icons.eot");
src: url("../../fonts/Simple-Line-Icons.eot?#iefix") format("embedded-opentype"), url("../../fonts/Simple-Line-Icons.woff") format("woff"), url("../../fonts/Simple-Line-Icons.ttf") format("truetype"), url("../../fonts/Simple-Line-Icons.svg#Simple-Line-Icons") format("svg");
font-weight: normal;
font-style: normal;
}
I understand that the url(../.. part is a problem for rails. What I can't figure out is how to solve it.
I have rails-12factor gem installed in my production environment. I've tried a million variations (shown in the rails guides), but I can't find anything that works.
Can anyone see what to do?
This article suggests not to include the 'fonts' folder in referencing vendor assets font files. https://gist.github.com/iamatypeofwalrus/6467148
I've tried including and excluding it but neither way works.
This article suggests that vendor file is not capable of storing fonts without amending the initialiser. I tried that but it doesnt work either.
Using fonts with Rails asset pipeline
Rails.application.config.assets.paths
=> ["/Users/cf3/app/assets/images", "/Users/cf3/app/assets/javascripts", "/Users/cf3/app/assets/stylesheets", "/Users/cf3/vendor/assets/fonts", "/Users/cf3/vendor/assets/javascripts", "/Users/cf3/vendor/assets/stylesheets", "/Users/lem/.rvm/gems/ruby-2.3.0/gems/underscore-rails-1.8.3/vendor/assets/javascripts", "/Users/lem/.rvm/gems/ruby-2.3.0/gems/gmaps4rails-2.1.2/vendor/assets/javascripts", "/Users/lem/.rvm/gems/ruby-2.3.0/gems/chosen-rails-1.4.3/vendor/assets/images", "/Users/lem/.rvm/gems/ruby-2.3.0/gems/chosen-rails-1.4.3/vendor/assets/javascripts", "/Users/lem/.rvm/gems/ruby-2.3.0/gems/chosen-rails-1.4.3/vendor/assets/stylesheets", "/Users/lem/.rvm/gems/ruby-2.3.0/gems/chartkick-1.4.1/app/assets/javascripts", "/Users/lem/.rvm/gems/ruby-2.3.0/gems/formtastic-2.2.1/app/assets/stylesheets", "/Users/lem/.rvm/gems/ruby-2.3.0/bundler/gems/surveyor-5281b317a559/lib/assets/images", "/Users/lem/.rvm/gems/ruby-2.3.0/bundler/gems/surveyor-5281b317a559/lib/assets/javascripts", "/Users/lem/.rvm/gems/ruby-2.3.0/bundler/gems/surveyor-5281b317a559/lib/assets/stylesheets", "/Users/lem/.rvm/gems/ruby-2.3.0/gems/dependent-fields-rails-0.4.2/vendor/assets/javascripts", "/Users/lem/.rvm/gems/ruby-2.3.0/gems/cocoon-1.2.6/app/assets/javascripts", "/Users/lem/.rvm/gems/ruby-2.3.0/gems/jquery-rails-4.0.5/vendor/assets/javascripts", "/Users/lem/.rvm/gems/ruby-2.3.0/gems/coffee-rails-4.1.0/lib/assets/javascripts", "/Users/lem/.rvm/gems/ruby-2.3.0/bundler/gems/momentjs-rails-eda1b74512db/vendor/assets/javascripts", "/Users/lem/.rvm/gems/ruby-2.3.0/gems/bootstrap-slider-rails-5.3.1/vendor/assets/javascripts", "/Users/lem/.rvm/gems/ruby-2.3.0/gems/bootstrap-slider-rails-5.3.1/vendor/assets/stylesheets", "Rails/vendor/assets/fonts", "/Users/lem/.rvm/gems/ruby-2.3.0/gems/bootstrap-sass-3.3.5.1/assets/stylesheets", "/Users/lem/.rvm/gems/ruby-2.3.0/gems/bootstrap-sass-3.3.5.1/assets/javascripts", "/Users/lem/.rvm/gems/ruby-2.3.0/gems/bootstrap-sass-3.3.5.1/assets/fonts", "/Users/lem/.rvm/gems/ruby-2.3.0/gems/bootstrap-sass-3.3.5.1/assets/images", "/Users/lem/.rvm/gems/ruby-2.3.0/gems/font-awesome-sass-4.4.0/assets/stylesheets", "/Users/lem/.rvm/gems/ruby-2.3.0/gems/font-awesome-sass-4.4.0/assets/fonts"]
HEROKU
I've now found this post, that suggests that for heroku compliance in production, I need to replace everything with asset path helpers and rename the files to add .erb to images and css and .coffee to js. Before I do this, can someone please confirm this is actually required, and how I would go about changing the above css file to comply with heroku requirements.
http://joanswork.com/wrapbootstrap-theme-to-rails/
Actually any sub-directory added to assets directory is auto added to the load
paths. Files in those directories can be accessed as normal asset
files.
If you have
vendor/assets/fonts/Simple-Line-Icons.eot
then vendor/assets/fonts/ should be added to load paths.
Then you can add all font files to your css files with path : font/file_name
Remember to restart your server after this as load paths will reload after restarting the server.
You can see the list of load paths through rails console by following command :
Rails.application.config.assets.paths
You can add new load paths by following command :
config.assets.paths << Rails.root.join("vendor", "assets", "fonts")
OR to autoload : config.autoload_paths << Rails.root.join("vendor", "assets", "fonts")

Resources