33 Author Tobias Koppers @sokra
44*/
55var ModuleParserHelpers = require ( "./ModuleParserHelpers" ) ;
6+ var ConstDependency = require ( "./dependencies/ConstDependency" ) ;
7+
8+ var NullFactory = require ( "./NullFactory" ) ;
69
710function ProvidePlugin ( definitions ) {
811 this . definitions = definitions ;
912}
1013module . exports = ProvidePlugin ;
1114ProvidePlugin . prototype . apply = function ( compiler ) {
15+ compiler . plugin ( "compilation" , function ( compilation , params ) {
16+ compilation . dependencyFactories . set ( ConstDependency , new NullFactory ( ) ) ;
17+ compilation . dependencyTemplates . set ( ConstDependency , new ConstDependency . Template ( ) ) ;
18+ } ) ;
1219 Object . keys ( this . definitions ) . forEach ( function ( name ) {
1320 var request = this . definitions [ name ] ;
1421 compiler . parser . plugin ( "expression " + name , function ( expr ) {
15- return ModuleParserHelpers . addParsedVariable ( this , name , "require(" + JSON . stringify ( request ) + ")" ) ;
22+ var nameIdentifier = name ;
23+ var scopedName = name . indexOf ( "." ) >= 0 ;
24+ if ( scopedName ) {
25+ nameIdentifier = "__webpack_provided_" + name . replace ( / \. / g, "_dot_" ) ;
26+ }
27+ if ( ! ModuleParserHelpers . addParsedVariable ( this , nameIdentifier , "require(" + JSON . stringify ( request ) + ")" ) ) {
28+ return false ;
29+ }
30+ if ( scopedName ) {
31+ nameIdentifier = "__webpack_provided_" + name . replace ( / \. / g, "_dot_" ) ;
32+ var dep = new ConstDependency ( nameIdentifier , expr . range ) ;
33+ dep . loc = expr . loc ;
34+ this . state . current . addDependency ( dep ) ;
35+ }
36+ return true ;
1637 } ) ;
1738 } , this ) ;
1839} ;
0 commit comments