-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
27 lines (24 loc) · 943 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
var loaderUtils = require("loader-utils");
module.exports = function() {};
module.exports.pitch = function(remainingRequest) {
this.cacheable && this.cacheable();
var options = loaderUtils.parseQuery(this.query);
var useExport = options.export ? '.' + options.export : '';
var moduleRequest = loaderUtils.stringifyRequest(this, remainingRequest);
var modulePath = loaderUtils.stringifyRequest(this, this.resourcePath);
var result = [
"var moduleInstance = require(" + moduleRequest + ");",
"var moduleId = require.resolve(" + moduleRequest + ");",
"module.exports = function(cb) {",
" cb(moduleInstance" + useExport + ");",
" if(module.hot) {",
" module.hot.accept([moduleId], function() {",
" console.log('Hot updating "+modulePath+"');",
" moduleInstance = require(" + moduleRequest + ");",
" cb(moduleInstance" + useExport + ");",
" });",
" }",
"}"
];
return result.join("\n");
};