Skip to content

Commit 35d15c7

Browse files
committed
fixes webpack#62
1 parent 898d425 commit 35d15c7

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

lib/node/NodeSourceRealPathsPlugin.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,26 @@
22
MIT License http://www.opensource.org/licenses/mit-license.php
33
Author Tobias Koppers @sokra
44
*/
5-
function NodeSourceRealPathsPlugin() {
5+
var path = require("path");
6+
7+
function NodeSourceRealPathsPlugin(context) {
8+
this.context = context;
69
}
710
module.exports = NodeSourceRealPathsPlugin;
811
NodeSourceRealPathsPlugin.prototype.apply = function(compiler) {
12+
var context = this.context;
913
compiler.parser.plugin("expression __filename", function(expr) {
1014
if(!this.state.module) return false;
11-
this.state.current.addVariable("__filename", JSON.stringify(this.state.module.resource));
15+
this.state.current.addVariable("__filename", JSON.stringify(
16+
context ? path.relative(context, this.state.module.resource) : this.state.module.resource
17+
));
1218
return true;
1319
});
1420
compiler.parser.plugin("expression __dirname", function(expr) {
1521
if(!this.state.module) return false;
16-
this.state.current.addVariable("__dirname", JSON.stringify(this.state.module.context));
22+
this.state.current.addVariable("__dirname", JSON.stringify(
23+
context ? path.relative(context, this.state.module.context) : this.state.module.context
24+
));
1725
return true;
1826
});
1927
};

0 commit comments

Comments
 (0)