thasmo
thasmo

Reputation: 9957

How to properly package loadCSS and cssrelpreload using webpack 2?

I'm trying to package filamentgroup/loadCSS using webpack 2 but I fail to do so. I'd like to get cssrelpreload.js executed in the browser so it preloads CSS files for browsers which do not support rel="preload".

I've tried using imports-loader and exports-loader to have window.loadCSS available for cssrelpreload.js but I'm unable configure it correctly.

I was able to get window available for loadCSS.js, but that doesn't help to get cssrelpreload.js executed correctly.

How would I need to configure webpack to get this packaged correctly?

Upvotes: 3

Views: 1256

Answers (2)

zalog
zalog

Reputation: 723

This worked for me:

import cssrelpreload from 'fg-loadcss/src/cssrelpreload.js'; // eslint-disable-line no-unused-vars

I've added eslint-disable-line because we don't use that imported var.

Upvotes: 0

Vladimir  Yazykov
Vladimir Yazykov

Reputation: 21

Try the following code

import { loadCSS } from 'fg-loadcss';
loadCSS( 'style.css' );

Upvotes: 2

Related Questions