isomorphic-style-loader-react18
Version:
CSS style loader for Webpack optimized for critical path CSS rendering and isomorphic web apps
44 lines (39 loc) • 1.67 kB
JavaScript
/**
* Isomorphic CSS style loader for Webpack
*
* Copyright © 2015-present Kriasoft, LLC. All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE.txt file in the root directory of this source tree.
*/
const { stringifyRequest } = require('loader-utils');
module.exports = function loader() { }
module.exports.pitch = function pitch(request) {
if (this.cacheable) {
this.cacheable()
}
const insertCss = require.resolve('./insertCss.js')
return `
var refs = 0;
var css = require(${stringifyRequest(this, `!!${request}`)});
var css_default = css.default || css;
var insertCss = require(${stringifyRequest(this, `!${insertCss}`)});
var content = typeof css_default === 'string' ? [[module.id, css_default, '']] : css_default;
exports = module.exports = css_default.locals || {};
exports._getContent = function() { return content; };
exports._getCss = function() { return '' + css_default; };
exports._insertCss = function(options) { return insertCss(content, options) };
// Hot Module Replacement
// https://webpack.github.io/docs/hot-module-replacement
// Only activated in browser context
if (module.hot && typeof window !== 'undefined' && window.document) {
var removeCss = function() {};
module.hot.accept(${stringifyRequest(this, `!!${request}`)}, function() {
css = require(${stringifyRequest(this, `!!${request}`)});
content = typeof css === 'string' ? [[module.id, css, '']] : css;
removeCss = insertCss(content, { replace: true });
});
module.hot.dispose(function() { removeCss(); });
}
`
}