Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webpack imports the same styles multiple times

I've noticed, that my webpack configuration imports the same styles into head <style> tag multiple times, when I @import styles in sass file.

Imported Styles

I think it's because of my global styles file, which looks like this:

@import url('https://fonts.googleapis.com/icon?family=Material+Icons');
@import '~material-design-lite/src/material-design-lite.scss';

I later import the styles in multiple other component style files:

@import 'global';

Is there some configuration that I've missed?
I thought I could import the global styles file in index.js file through import, but these imports must come first, and somehow I was not able to achieve that with webpack.

like image 699
Vincas Stonys Avatar asked Sep 24 '16 10:09

Vincas Stonys


1 Answers

That's not an issue with webpack, more with your use of CSS. Since CSS assets are compiled statically, each stylesheet importing global has a copy in it. You could use Less, and the @import (reference) statement, or if you prefer CSS then load it separately and don't import it every time.

like image 179
eavidan Avatar answered Nov 04 '22 04:11

eavidan