2012-04-07 05:06:57 +04:00
|
|
|
/*
|
2016-07-26 11:49:11 +03:00
|
|
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
|
|
Author Tobias Koppers @sokra
|
|
|
|
*/
|
2014-10-20 20:22:46 +04:00
|
|
|
var loaderUtils = require("loader-utils"),
|
2016-07-26 11:49:11 +03:00
|
|
|
path = require("path"),
|
|
|
|
universal = require('./universal');
|
2013-01-28 18:06:19 +04:00
|
|
|
module.exports = function() {};
|
|
|
|
module.exports.pitch = function(remainingRequest) {
|
2015-04-25 15:46:32 +03:00
|
|
|
if(this.cacheable) this.cacheable();
|
2017-02-24 13:39:44 +03:00
|
|
|
var query = loaderUtils.getOptions(this) || {};
|
2014-08-14 13:12:19 +04:00
|
|
|
return [
|
|
|
|
"// style-loader: Adds some css to the DOM by adding a <style> tag",
|
2014-09-08 00:23:54 +04:00
|
|
|
"",
|
|
|
|
"// load the styles",
|
2015-04-10 00:46:55 +03:00
|
|
|
"var content = require(" + loaderUtils.stringifyRequest(this, "!!" + remainingRequest) + ");",
|
2014-09-30 01:22:41 +04:00
|
|
|
"if(typeof content === 'string') content = [[module.id, content, '']];",
|
2015-04-25 15:46:32 +03:00
|
|
|
"if(content.locals) module.exports = content.locals;",
|
2016-07-24 19:20:42 +03:00
|
|
|
"if (typeof window === 'undefined') {",
|
2016-07-26 11:49:11 +03:00
|
|
|
" require(" + loaderUtils.stringifyRequest(this, "!" + path.join(__dirname, "universal.js")) + ").addStyles(content, " + JSON.stringify(query) + ");",
|
2016-07-24 19:20:42 +03:00
|
|
|
"} else {",
|
2016-07-24 19:39:27 +03:00
|
|
|
"// add the styles to the DOM",
|
2016-07-24 19:20:42 +03:00
|
|
|
"var update = require(" + loaderUtils.stringifyRequest(this, "!" + path.join(__dirname, "addStyles.js")) + ")(content, " + JSON.stringify(query) + ");",
|
2014-08-14 13:12:19 +04:00
|
|
|
"// Hot Module Replacement",
|
|
|
|
"if(module.hot) {",
|
2014-09-08 00:23:54 +04:00
|
|
|
" // When the styles change, update the <style> tags",
|
2015-04-25 15:46:32 +03:00
|
|
|
" if(!content.locals) {",
|
2015-04-22 00:35:55 +03:00
|
|
|
" module.hot.accept(" + loaderUtils.stringifyRequest(this, "!!" + remainingRequest) + ", function() {",
|
|
|
|
" var newContent = require(" + loaderUtils.stringifyRequest(this, "!!" + remainingRequest) + ");",
|
|
|
|
" if(typeof newContent === 'string') newContent = [[module.id, newContent, '']];",
|
|
|
|
" update(newContent);",
|
|
|
|
" });",
|
|
|
|
" }",
|
2014-09-08 00:23:54 +04:00
|
|
|
" // When the module is disposed, remove the <style> tags",
|
|
|
|
" module.hot.dispose(function() { update(); });",
|
2016-07-24 19:39:27 +03:00
|
|
|
"}",
|
2014-08-14 13:12:19 +04:00
|
|
|
"}"
|
|
|
|
].join("\n");
|
2013-01-28 18:06:19 +04:00
|
|
|
};
|
2016-07-26 11:49:11 +03:00
|
|
|
|
|
|
|
module.exports.getStyles = universal.getStyles
|