mirror of
https://github.com/elyby/accounts-frontend.git
synced 2024-11-15 12:46:04 +05:30
35 lines
931 B
JavaScript
35 lines
931 B
JavaScript
var loaderUtils = require("loader-utils");
|
|
|
|
module.exports = function createImporter(options) {
|
|
return function(url, fileContext, done) {
|
|
if (options.test.test(url)) {
|
|
var request = loaderUtils.urlToRequest(url);
|
|
|
|
loaderContext.loadModule(request, function(err, source) {
|
|
if (err) return done(new Error(err));
|
|
|
|
done({
|
|
contents: loaderContext.exec(source)
|
|
});
|
|
});
|
|
} else {
|
|
done(false);
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
var loaderContext;
|
|
var Plugin = module.exports.Plugin = function() {};
|
|
|
|
Plugin.prototype.apply = function(compiler) {
|
|
compiler.plugin('compilation', function(compilation) {
|
|
compilation.plugin('normal-module-loader', setLoaderContext);
|
|
});
|
|
};
|
|
|
|
function setLoaderContext(instance) {
|
|
// inject loaderContext instance for importer function
|
|
loaderContext = instance;
|
|
}
|