UNPKG

1.11 kBJavaScriptView Raw
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5
6var path = require('path');
7
8function accesorString(value) {
9 var childProperties = value.split(".");
10 var length = childProperties.length;
11 var propertyString = "global";
12 var result = "";
13
14 for(var i = 0; i < length; i++) {
15 if(i > 0)
16 result += "if(!" + propertyString + ") " + propertyString + " = {};\n";
17 propertyString += "[" + JSON.stringify(childProperties[i]) + "]";
18 }
19
20 result += "module.exports = " + propertyString;
21 return result;
22}
23
24module.exports = function() {};
25module.exports.pitch = function(remainingRequest) {
26 // Change the request from an /abolute/path.js to a relative ./path.js
27 // This prevents [chunkhash] values from changing when running webpack
28 // builds in different directories.
29 var newRequestPath = "." + path.sep + path.basename(remainingRequest);
30 this.cacheable && this.cacheable();
31 if(!this.query) throw new Error("query parameter is missing");
32 return accesorString(this.query.substr(1)) + " = " +
33 "require(" + JSON.stringify("-!" + newRequestPath) + ");";
34};