neutrinojs / neutrino

Create and build modern JavaScript projects with zero initial configuration.
https://neutrinojs.org
Mozilla Public License 2.0
3.95k stars 213 forks source link

Question: Load fonts using url to benefit from CDN and caching #1595

Closed woss closed 4 years ago

woss commented 4 years ago

HI, I've been reading the docs and i can't find the way to inject the <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet"> into the template?

I use react preset with latest neurtino. Can you help me out with this?

woss commented 4 years ago

I sovled it by copying the default template from this repo and using the https://neutrinojs.org/packages/web/#preset-options to set the proper path and then changed the template, this will also work with react because react extends the web preset

constgen commented 4 years ago

Look toward the way to include a custom Wepack plugin in your .neutrinorc.js file. The plugin you should use is https://www.npmjs.com/package/google-fonts-webpack-plugin . I enabled it like this

neutrino.config.plugin('fonts')
        .use(GoogleFontsPlugin, [{
          fonts: [
            {
              family: 'Roboto',
              variants: ['300', '400', '500'],
              subsets: ['latin', 'latin-ext', 'vietnamese', 'greek', 'greek-ext', 'cyrillic', 'cyrillic-ext']
            }
          ],
          local: false
        }]);