Skip to content

Commit 075f471

Browse files
committed
Update loader.js
Hi, I have not fully tested this but the basic concept seems to work as far as I have tried it. There is currently a pretty big issue regarding including less and scss files from node packages because most of them are compiled into different directories than where the src file resides. This messes with relative resources. With this minor change people can specify a rel path to trick relative resources to load relative to the supplied path. example usage: ``` module: { loaders: [ { test: /\.less$/, loader: ["style-loader", "css-loader", "less-loader"], exclude: [ /\package\/less\/style.less$/ ] }, { test: /\package\/less\/style.less$/, loader: [ "style-loader", "css-loader?rel="+path.resolve(__dirname,'path/to/package/dist/css'), "less-loader" ] } ] } ``` I just pulled the regx code off of stack overflow. Not sure what the best practice is to detect if a path is relative in javascript.
1 parent b6acfec commit 075f471

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

lib/loader.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module.exports = function(content, map) {
1414
var callback = this.async();
1515
var query = loaderUtils.parseQuery(this.query);
1616
var root = query.root;
17+
var rel = query.rel;
1718
var moduleMode = query.modules || query.module;
1819
var camelCaseKeys = query.camelCase || query.camelcase;
1920

@@ -81,6 +82,9 @@ module.exports = function(content, map) {
8182
url.substr(idx);
8283
}
8384
urlRequest = url;
85+
if(!(/^(?:\/|[a-z0-9]+:\/\/)/.test(urlRequest)) && typeof rel !== 'undefined' ) {
86+
urlRequest = rel + "/" + urlRequest;
87+
}
8488
return "\" + require(" + loaderUtils.stringifyRequest(this, urlRequest) + ") + \"";
8589
}.bind(this));
8690
}

0 commit comments

Comments
 (0)