style-resources-loader icon indicating copy to clipboard operation
style-resources-loader copied to clipboard

Fail to import google fonts with sass

Open snowman opened this issue 5 years ago • 6 comments

// FILE: vue.config.js
const path = require("path")

module.exports = {
  pluginOptions: {
    ...
    'style-resources-loader': {
      preProcessor: 'sass',
      patterns: [
        path.resolve(__dirname, 'src/assets/styles/main.sass')
      ]
    }
    ...
  }
}
// FILE: main.sass
@import url('https://fonts.googleapis.com/css?family=Karla:400,700|Rubik:400,500,700')

Error:

File to import not found or unreadable: ../assets/styles/url('https://fonts.googleapis.co│
m/css?family=Karla:400,700|Rubik:400,500,700')

snowman avatar Apr 02 '19 10:04 snowman

SOLUTION

// FILE: src/assets/styles/base/_typography.sass
@import url('https://fonts.googleapis.com/css?family=Karla:400,700|Rubik:400,500,700')
// FILE: main.sass
@import 'base/typography'

snowman avatar Apr 02 '19 11:04 snowman

It must be a bug when the loader resolves @import url(). I will fix this. Thanks for reporting.

yenshih avatar Apr 02 '19 15:04 yenshih

I am still experiencing the exact same issue as @snowman, moving the type imports to a separate file worked fine.

danhorton7 avatar Mar 03 '20 22:03 danhorton7

It's a problem with sass-resources-loader as well: https://github.com/webpack/webpack/issues/8865#issuecomment-472998437

mihailthebuilder avatar Nov 19 '20 13:11 mihailthebuilder

Actually it's not a problem. Statements like @import url('https://fonts.googleapis.com/css?family=Karla:400,700|Rubik:400,500,700') is not preferred to inject into all style files, they may be imported only once.

yenshih avatar Nov 20 '20 10:11 yenshih

Also, moving those url imports from your .scss file to your index.html file should work fine.

nobi1007 avatar Dec 31 '20 08:12 nobi1007