styles-to-js-loader
Webpack loader to enables access to external styles from JavaScript
Installation
npm install styles-to-js-loader --save
Usage
In webpack config use the loader for your css/style files.
test: /\.css$/ use: "styles-to-js-loader" "css-loader"
Access styles in JavaScript.
;styles <style>
Usefull to get external styles into a web component.
;; { super; const shadow = this; shadow; }
styles.find function
While styles.get()
returns a style tag with all the styles for every imported style file the styles.find()
function tries to find a single files content by its imported name.
styles
In the example below we fetch only the owp.glyphicons
styles and then extract the font face to add to the header.
//Add glyphicons fonts to header or else they wont be loaded.documenthead;