Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: manage loader resolution with webpack #287

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions lib/getImportPrefix.js

This file was deleted.

14 changes: 6 additions & 8 deletions lib/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
var path = require("path");
var loaderUtils = require("loader-utils");
var processCss = require("./processCss");
var getImportPrefix = require("./getImportPrefix");
var compileExports = require("./compile-exports");


module.exports = function(content, map) {
if(this.cacheable) this.cacheable();
var callback = this.async();
Expand All @@ -33,8 +31,9 @@ module.exports = function(content, map) {

var cssAsString = JSON.stringify(result.source);

// for importing CSS
var importUrlPrefix = getImportPrefix(this, query);
result.importItems.forEach(function(imp) {
this.addDependency(imp.url);
}.bind(this));

var alreadyImported = {};
var importJs = result.importItems.filter(function(imp) {
Expand All @@ -50,17 +49,16 @@ module.exports = function(content, map) {
JSON.stringify("@import url(" + imp.url + ");") + ", " +
JSON.stringify(imp.mediaQuery) + "]);";
} else {
var importUrl = importUrlPrefix + imp.url;
return "exports.i(require(" + loaderUtils.stringifyRequest(this, importUrl) + "), " + JSON.stringify(imp.mediaQuery) + ");";
return "exports.i(require(" + loaderUtils.stringifyRequest(this,
imp.url) + "), " + JSON.stringify(imp.mediaQuery) + ");";
}
}, this).join("\n");

function importItemMatcher(item) {
var match = result.importItemRegExp.exec(item);
var idx = +match[1];
var importItem = result.importItems[idx];
var importUrl = importUrlPrefix + importItem.url;
return "\" + require(" + loaderUtils.stringifyRequest(this, importUrl) + ").locals" +
return "\" + require(" + loaderUtils.stringifyRequest(this, importItem.url) + ")" +
"[" + JSON.stringify(importItem.export) + "] + \"";
}

Expand Down
8 changes: 1 addition & 7 deletions lib/localsLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
*/
var loaderUtils = require("loader-utils");
var processCss = require("./processCss");
var getImportPrefix = require("./getImportPrefix");
var compileExports = require("./compile-exports");


module.exports = function(content) {
if(this.cacheable) this.cacheable();
var callback = this.async();
Expand All @@ -23,15 +21,11 @@ module.exports = function(content) {
}, function(err, result) {
if(err) return callback(err);

// for importing CSS
var importUrlPrefix = getImportPrefix(this, query);

function importItemMatcher(item) {
var match = result.importItemRegExp.exec(item);
var idx = +match[1];
var importItem = result.importItems[idx];
var importUrl = importUrlPrefix + importItem.url;
return "\" + require(" + loaderUtils.stringifyRequest(this, importUrl) + ")" +
return "\" + require(" + JSON.stringify(importItem.url) + ")" +
"[" + JSON.stringify(importItem.export) + "] + \"";
}

Expand Down
1 change: 1 addition & 0 deletions test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ function assetEvaluated(output, result, modules) {

function runLoader(loader, input, map, addOptions, callback) {
var opt = {
addDependency: function(url) {},
options: {
context: ""
},
Expand Down