React-redux-universal-hot-example: When including a font in scss file it works, but I get an error in chrome console.

Created on 5 Feb 2016  路  4Comments  路  Source: erikras/react-redux-universal-hot-example

If I place some fonts files in /static/icon-fonts/... and include the following in app.scss

@font-face {
    font-family: 'socialIcons';
    src: url('/icon-fonts/socicon-1.3/socicon.eot');
    src: url('/icon-fonts/socicon-1.3/socicon.eot?#iefix') format('embedded-opentype'),
         url('/icon-fonts/socicon-1.3/socicon.woff') format('woff'),
         url('/icon-fonts/socicon-1.3/socicon.ttf') format('truetype'),
         url('/icon-fonts/socicon-1.3/socicon.svg#icomoonregular') format('svg');
    font-weight: normal;
    font-style: normal;
}

The font works but I get errors in the chrome console.

Failed to decode downloaded font: http://localhost:3000/
(index):1 OTS parsing error: invalid version tag

I've tried multiple fonts, so it is not a problem with the file.

I found this stackoverflow post. But the webpack config already is including the host and port.

Any ideas?

Most helpful comment

Well I now know a lot more about webpack than I did before...

I solved this by using resolve-url-loader to convert the urls for the fonts into a relative form that webpack could find.

npm i --save resolve-url-loader

Then I created a fonts folder in the same directory as app.scss and referenced them as:

@font-face {
    font-family: 'socialIcons';
    src: url('fonts/socicon.eot');
    .....
}

Finally I changed the following line in /webpack/dev.config

  { test: /\.scss$/, loader: 'style!css?modules&importLoaders=2&sourceMap&localIdentName=[local]___[hash:base64:5]!autoprefixer?browsers=last 2 version!sass?outputStyle=expanded&sourceMap' },

to be (I added !resolve-url before !sass)

      { test: /\.scss$/, loader: 'style!css?modules&importLoaders=2&sourceMap&localIdentName=[local]___[hash:base64:5]!autoprefixer?browsers=last 2 version!resolve-url!sass?outputStyle=expanded&sourceMap' },

and the following line in /webpack/prod.config

      { test: /\.scss$/, loader: ExtractTextPlugin.extract('style', 'css?modules&importLoaders=2&sourceMap!autoprefixer?browsers=last 2 version!sass?outputStyle=expanded&sourceMap=true&sourceMapContents=true') },

to be:

  { test: /\.scss$/, loader: ExtractTextPlugin.extract('style', 'css?modules&importLoaders=2&sourceMap!autoprefixer?browsers=last 2 version!resolve-url!sass?outputStyle=expanded&sourceMap=true&sourceMapContents=true') },

All 4 comments

Well I now know a lot more about webpack than I did before...

I solved this by using resolve-url-loader to convert the urls for the fonts into a relative form that webpack could find.

npm i --save resolve-url-loader

Then I created a fonts folder in the same directory as app.scss and referenced them as:

@font-face {
    font-family: 'socialIcons';
    src: url('fonts/socicon.eot');
    .....
}

Finally I changed the following line in /webpack/dev.config

  { test: /\.scss$/, loader: 'style!css?modules&importLoaders=2&sourceMap&localIdentName=[local]___[hash:base64:5]!autoprefixer?browsers=last 2 version!sass?outputStyle=expanded&sourceMap' },

to be (I added !resolve-url before !sass)

      { test: /\.scss$/, loader: 'style!css?modules&importLoaders=2&sourceMap&localIdentName=[local]___[hash:base64:5]!autoprefixer?browsers=last 2 version!resolve-url!sass?outputStyle=expanded&sourceMap' },

and the following line in /webpack/prod.config

      { test: /\.scss$/, loader: ExtractTextPlugin.extract('style', 'css?modules&importLoaders=2&sourceMap!autoprefixer?browsers=last 2 version!sass?outputStyle=expanded&sourceMap=true&sourceMapContents=true') },

to be:

  { test: /\.scss$/, loader: ExtractTextPlugin.extract('style', 'css?modules&importLoaders=2&sourceMap!autoprefixer?browsers=last 2 version!resolve-url!sass?outputStyle=expanded&sourceMap=true&sourceMapContents=true') },

Thanks for this update. Very helpful :+1:

Saved me the afternoon. Thanks a lot @skywickenden

@skywickenden thanks a million

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jorgehmv picture jorgehmv  路  3Comments

c089 picture c089  路  5Comments

chrisabrams picture chrisabrams  路  5Comments

eromoe picture eromoe  路  5Comments

massimopibiri picture massimopibiri  路  5Comments