Preact-cli: Adding Google Fonts

Created on 17 Jul 2017  路  2Comments  路  Source: preactjs/preact-cli

Is there any way to add to the index file to include Google Fonts?

question

Most helpful comment

Totes - 3 options for this that I'm aware of.

  1. Import it from some css:
// index.js
import './style/index.css';
/* style/index.css */
@import url('//fonts.googleapis.com/css?family=Open+Sans');
  1. You can SSR it!
// index.js
export default () => (
  <div class="app">
    <link rel="stylesheet" href="//fonts.googleapis.com/css?family=Open+Sans" />
    {/* regular app stuff here */}
  </div>
);
  1. Specify a custom HTML template and make it all your own. I recommend starting from the internal default HTML template:
preact build --html-template my-template.html

3.1 - you can also set the template from preact.config.js:

// preact.config.js in your repo root
export default (config, env, helpers) => {
 helpers.setHtmlTemplate(config, 'src/index.html');
};

The only issue with --html-template is that if preact-cli updates need a new template, you'll still have your custom one. If you can use VDOM to render the fonts, that'll be better.

All 2 comments

Totes - 3 options for this that I'm aware of.

  1. Import it from some css:
// index.js
import './style/index.css';
/* style/index.css */
@import url('//fonts.googleapis.com/css?family=Open+Sans');
  1. You can SSR it!
// index.js
export default () => (
  <div class="app">
    <link rel="stylesheet" href="//fonts.googleapis.com/css?family=Open+Sans" />
    {/* regular app stuff here */}
  </div>
);
  1. Specify a custom HTML template and make it all your own. I recommend starting from the internal default HTML template:
preact build --html-template my-template.html

3.1 - you can also set the template from preact.config.js:

// preact.config.js in your repo root
export default (config, env, helpers) => {
 helpers.setHtmlTemplate(config, 'src/index.html');
};

The only issue with --html-template is that if preact-cli updates need a new template, you'll still have your custom one. If you can use VDOM to render the fonts, that'll be better.

Nice - thanks for taking time to show the options. Works great.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

andybons picture andybons  路  3Comments

jpoo90 picture jpoo90  路  4Comments

nephix picture nephix  路  4Comments

smjnab picture smjnab  路  3Comments

AlStar01 picture AlStar01  路  3Comments