How do I add a Google Font to a VueJS Component?

前端 未结 7 1917
离开以前
离开以前 2021-02-03 20:42

I\'ve been trying for an hour to find a way to import a Google Font into a VueJS Component, but I cannot seem to find a solution, nothing worked yet, not even the stuff from pre

7条回答
  •  野性不改
    2021-02-03 21:20

    Imo, if you're using VueJS, Google Fonts Webpack Plugin is the way.

    Here's the plugin, it's really easy to set it up and works like a charm.

    npm i google-fonts-webpack-plugin -D

    Go to your /webpack.config.js / webpack.base.config.js and add the following lines:

    const GoogleFontsPlugin = require("google-fonts-webpack-plugin")
    
    module.exports = {
        "entry": "index.js",
        /* ... */
        plugins: [
            new GoogleFontsPlugin({
                fonts: [
                    { family: "Source Sans Pro" },
                    { family: "Roboto", variants: [ "400", "700italic" ] }
                ]
            })
        ]
    }
    

    Now you can use Google Fonts anywhere inside your VueJS project :)

提交回复
热议问题