UNPKG

isomorphic-style-loader

Version:

CSS style loader for Webpack optimized for critical path CSS rendering and isomoprhic web apps

49 lines (43 loc) 1.62 kB
/** * 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. */ import { stringifyRequest } from '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 css = require(${stringifyRequest(this, `!!${request}`)}); var insertCss = require(${stringifyRequest(this, `!${insertCss}`)}); var content = typeof css === 'string' ? [[module.id, css, '']] : css; exports = module.exports = css.locals || {}; exports._getContent = function() { return content; }; exports._getCss = function() { return '' + css; }; exports._insertCss = function(options) { return insertCss(content, options) }; ${ this.hot ? ` // 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(); }); } ` : '' } ` }