@@ -3,6 +3,7 @@ var findRoot = require('find-root')
3
3
, resolve = require ( 'resolve' )
4
4
, get = require ( 'lodash.get' )
5
5
, find = require ( 'array-find' )
6
+ , interpret = require ( 'interpret' )
6
7
// not available on 0.10.x
7
8
, isAbsolute = path . isAbsolute || require ( 'is-absolute' )
8
9
@@ -32,6 +33,7 @@ exports.resolve = function (source, file, settings) {
32
33
33
34
var configPath = get ( settings , 'config' , 'webpack.config.js' )
34
35
, webpackConfig
36
+
35
37
try {
36
38
// see if we've got an absolute path
37
39
if ( ! isAbsolute ( configPath ) ) {
@@ -42,7 +44,19 @@ exports.resolve = function (source, file, settings) {
42
44
configPath = path . join ( packageDir , configPath )
43
45
}
44
46
47
+ var ext = Object . keys ( interpret . extensions ) . reduce ( function ( chosen , extension ) {
48
+ var extlen = extension . length
49
+ return ( ( configPath . substr ( - extlen ) === extension ) && ( extlen > chosen . length ) )
50
+ ? extension : chosen
51
+ } , '' )
52
+
53
+ registerCompiler ( interpret . extensions [ ext ] )
54
+
45
55
webpackConfig = require ( configPath )
56
+
57
+ if ( webpackConfig && webpackConfig . default ) {
58
+ webpackConfig = webpackConfig . default
59
+ }
46
60
} catch ( err ) {
47
61
webpackConfig = { }
48
62
}
@@ -57,10 +71,12 @@ exports.resolve = function (source, file, settings) {
57
71
58
72
// root as first alternate path
59
73
var rootPath = get ( webpackConfig , [ 'resolve' , 'root' ] )
74
+
60
75
if ( rootPath ) {
61
76
if ( typeof rootPath === 'string' ) paths . push ( rootPath )
62
77
else paths . push . apply ( paths , rootPath )
63
78
}
79
+
64
80
// set fallback paths
65
81
var fallbackPath = get ( webpackConfig , [ 'resolve' , 'fallback' ] )
66
82
if ( fallbackPath ) {
@@ -71,6 +87,7 @@ exports.resolve = function (source, file, settings) {
71
87
72
88
// otherwise, resolve "normally"
73
89
try {
90
+
74
91
return { found : true , path : resolve . sync ( source , {
75
92
basedir : path . dirname ( file ) ,
76
93
@@ -145,3 +162,23 @@ function packageFilter(config, pkg) {
145
162
146
163
return pkg
147
164
}
165
+
166
+
167
+ function registerCompiler ( moduleDescriptor ) {
168
+ if ( moduleDescriptor ) {
169
+ if ( typeof moduleDescriptor === 'string' ) {
170
+ require ( moduleDescriptor )
171
+ } else if ( ! Array . isArray ( moduleDescriptor ) ) {
172
+ moduleDescriptor . register ( require ( moduleDescriptor . module ) )
173
+ } else {
174
+ for ( var i = 0 ; i < moduleDescriptor . length ; i ++ ) {
175
+ try {
176
+ registerCompiler ( moduleDescriptor [ i ] )
177
+ break
178
+ } catch ( e ) {
179
+ // do nothing
180
+ }
181
+ }
182
+ }
183
+ }
184
+ }
0 commit comments