@@ -19,6 +19,7 @@ var ConsolePlugin = require("./ConsolePlugin");
1919var APIPlugin = require ( "./APIPlugin" ) ;
2020var ConstPlugin = require ( "./ConstPlugin" ) ;
2121var CompatibilityPlugin = require ( "./CompatibilityPlugin" ) ;
22+ var ProvidePlugin = require ( "./ProvidePlugin" ) ;
2223
2324var CommonJsPlugin = require ( "./dependencies/CommonJsPlugin" ) ;
2425var AMDPlugin = require ( "./dependencies/AMDPlugin" ) ;
@@ -102,12 +103,18 @@ WebpackOptionsApply.prototype.process = function(options, compiler) {
102103 if ( options . cache === undefined ? options . watch : options . cache )
103104 compiler . apply ( new CachePlugin ( typeof options . cache == "object" ? options . cache : null ) ) ;
104105
106+ if ( typeof options . provide === "object" ) {
107+ for ( var name in options . provide ) {
108+ compiler . apply ( new ProvidePlugin ( name , options . provide [ name ] ) ) ;
109+ }
110+ }
111+
105112 compiler . applyPlugins ( "after-plugins" , compiler ) ;
106113 compiler . resolvers . normal . apply (
107114 new ModuleAliasPlugin ( options . resolve . alias ) ,
108- makeRootPlugin ( options . resolve . root ) ,
115+ makeRootPlugin ( "module" , options . resolve . root ) ,
109116 new ModulesInDirectoriesPlugin ( "module" , options . resolve . modulesDirectories ) ,
110- makeRootPlugin ( options . resolve . fallback ) ,
117+ makeRootPlugin ( "module" , options . resolve . fallback ) ,
111118 new ModuleAsFilePlugin ( "module" ) ,
112119 new ModuleAsDirectoryPlugin ( "module" ) ,
113120 new DirectoryDescriptionFilePlugin ( "package.json" , [ "webpack" , "browserify" , "web" , [ "jam" , "main" ] , "main" ] ) ,
@@ -116,18 +123,18 @@ WebpackOptionsApply.prototype.process = function(options, compiler) {
116123 ) ;
117124 compiler . resolvers . context . apply (
118125 new ModuleAliasPlugin ( options . resolve . alias ) ,
119- makeRootPlugin ( options . resolve . root ) ,
126+ makeRootPlugin ( "module" , options . resolve . root ) ,
120127 new ModulesInDirectoriesPlugin ( "module" , options . resolve . modulesDirectories ) ,
121- makeRootPlugin ( options . resolve . fallback ) ,
128+ makeRootPlugin ( "module" , options . resolve . fallback ) ,
122129 new ModuleAsFilePlugin ( "module" ) ,
123130 new ModuleAsDirectoryPlugin ( "module" ) ,
124131 new DirectoryResultPlugin ( )
125132 ) ;
126133 compiler . resolvers . loader . apply (
127134 new ModuleAliasPlugin ( options . resolveLoader . alias ) ,
128- makeRootPlugin ( options . resolveLoader . root ) ,
135+ makeRootPlugin ( "loader-module" , options . resolveLoader . root ) ,
129136 new ModulesInDirectoriesPlugin ( "loader-module" , options . resolveLoader . modulesDirectories ) ,
130- makeRootPlugin ( options . resolveLoader . fallback ) ,
137+ makeRootPlugin ( "loader-module" , options . resolveLoader . fallback ) ,
131138 new ModuleTemplatesPlugin ( "loader-module" , options . resolveLoader . moduleTemplates , "module" ) ,
132139 new ModuleAsFilePlugin ( "module" ) ,
133140 new ModuleAsDirectoryPlugin ( "module" ) ,
@@ -139,9 +146,9 @@ WebpackOptionsApply.prototype.process = function(options, compiler) {
139146 return options ;
140147}
141148
142- function makeRootPlugin ( root ) {
149+ function makeRootPlugin ( name , root ) {
143150 if ( typeof root === "string" )
144- return new ModulesInRootPlugin ( "module" , root ) ;
151+ return new ModulesInRootPlugin ( name , root ) ;
145152 else if ( Array . isArray ( root ) ) {
146153 return function ( ) {
147154 root . forEach ( function ( root ) {
0 commit comments