Skip to content
This repository has been archived by the owner on Jul 19, 2021. It is now read-only.

Add custom fonts to slate 1.x #418

Closed
pveen2 opened this issue Feb 28, 2018 · 8 comments
Closed

Add custom fonts to slate 1.x #418

pveen2 opened this issue Feb 28, 2018 · 8 comments

Comments

@pveen2
Copy link

pveen2 commented Feb 28, 2018

Problem

In the folder src/assets/fonts i added a custom font so an eot, woff & woff2 file. But i can't use them with the SCSS files

Is there a workaround to add them to the scss?

@t-kelly
Copy link
Contributor

t-kelly commented Feb 28, 2018

Hey @pveen2 -- you'll need to declare the @font-face in your main layout file (theme.liquid) because you'll need to use liquid, more particularly the asset_url filter:

<style>
  @font-face {
    font-family: "Open Sans";
    src: url("{{ '../assets/fonts/opensans.woff2' | asset_url }}") format("woff2")
  }
</style>

and then reference you font as normal in your .scss file:

p {
  font-family: "Open Sans";
}

Does that work for you?

Related: #410

@pveen2
Copy link
Author

pveen2 commented Mar 5, 2018

Yes @t-kelly, thanks. I thought I already reply. But thanks!

@t-kelly t-kelly closed this as completed Mar 6, 2018
@zomars
Copy link

zomars commented May 8, 2018

It's not working for me unfortunately, the "assets/fonts" folder is being ignored.

@RustyDev
Copy link

RustyDev commented May 9, 2018

I've been wrestling with loading fonts for awhile. The only way I can get this to deploy, is by using global_asset_url. But then I get a 404 from the CDN. The assets/fonts folder is screwing things up:

404 : https://cdn.shopify.com/s/assets/fonts/GTAmerica-Regular.woff2

Here's my code in theme.liquid:

<style>
@font-face {
    font-family: 'GT America Condensed';
    src: url("{{ '../assets/fonts/GTAmerica-CondensedBold.woff2' | global_asset_url }}") format('woff2'),
        url("{{ '../assets/fonts/GTAmerica-CondensedBold.woff' | global_asset_url }}") format('woff');
    font-weight: bold;
    font-style: normal;
}
</style>

The lack of clear documentation around assets is really getting frustrating.

@t-kelly
Copy link
Contributor

t-kelly commented May 10, 2018

Sounds like this needs to be reopened. I'll take a look as soon as I have the chance!

@t-kelly t-kelly reopened this May 10, 2018
@dictions
Copy link

For those looking to solve this today, you can reference web font files from SCSS and the core webpack config will resolve the files. Note that OTFs do not work - see the loader config here.

My slate.config.js file:

const path = require('path');

const alias = {
	'lodash': path.resolve('./node_modules/lodash-es'),
	'scripts': path.resolve('./src/assets/scripts'),
	'styles': path.resolve('./src/assets/styles'),
	'fonts': path.resolve('./src/assets/fonts'),
};

module.exports = {
	slateTools: {
		extends: {
			dev: {
				resolve: {alias}
			},
			prod: {
				resolve: {alias}
			},
		},
	}
};

My fonts.scss file in assets/styles/...:

@font-face {
	font-family: 'Danzza';
	src: url('~fonts/Danzza-Medium.woff');
	font-weight: 500;
	font-style: normal;
}

@font-face {
	font-family: 'Windsor';
	src: url('~fonts/Windsor-Roman.woff');
	font-weight: 400;
	font-style: normal;
}

@font-face {
	font-family: 'Suisse';
	src: url('~fonts/SuisseIntlMono-Regular.woff');
	font-weight: 400;
	font-style: normal;
}

@t-kelly
Copy link
Contributor

t-kelly commented Oct 25, 2018

@t-kelly t-kelly closed this as completed Oct 25, 2018
@lock
Copy link

lock bot commented Nov 24, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Nov 24, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants