forked from webpack-contrib/restyle-loader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
30 lines (26 loc) · 834 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Daniel Verejan
*/
const path = require('path');
const loaderUtils = require('loader-utils');
module.exports = () => {};
module.exports.pitch = function pitch(remainingRequest) {
const modulePath = path.join(__dirname, 'lib/replace-style.js');
const moduleLoader = JSON.stringify(`!${modulePath}`);
const request = loaderUtils.stringifyRequest(this, `!!${remainingRequest}`);
if (this.cacheable) {
this.cacheable();
}
return `// restyle-loader: Search for a stylesheet <link> in the DOM and replace/update the href',
var update = require(${moduleLoader})(
require(${request})
);
// Hot Module Replacement
if(module.hot) {
module.hot.accept(${request}, function() {
update(require(${request}));
});
module.hot.dispose(update);
}`;
};