Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions resolvers/webpack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,17 @@ exports.resolveImport = function resolveImport(source, file, settings) {

var webpackConfig
try {
var packageDir = findRoot(file)
if (!packageDir) throw new Error('package not found above ' + file)

webpackConfig = require(path.join(packageDir, get(settings, 'config', 'webpack.config.js')))
} catch (err) {
webpackConfig = {}
// see if we've got an absolute path
webpackConfig = require(get(settings, 'config', null))
} catch(err) {
try {
var packageDir = findRoot(file)
if (!packageDir) throw new Error('package not found above ' + file)

webpackConfig = require(path.join(packageDir, get(settings, 'config', 'webpack.config.js')))
} catch (err) {
webpackConfig = {}
}
}

// externals
Expand Down
22 changes: 22 additions & 0 deletions resolvers/webpack/test/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
var chai = require('chai')
, expect = chai.expect

import { resolveImport as resolve } from '../index'

import path from 'path'

var file = path.join(__dirname, 'files', 'src', 'jsx', 'dummy.js')
var absoluteSettings = {
config: path.join(__dirname, 'files/some/absolute.path.webpack.config.js')
}

describe("config", function () {
it("finds webpack.config.js in parent directories", function () {
expect(resolve('main-module', file)).to.exist
.and.equal(path.join(__dirname, 'files', 'src', 'main-module.js'))
})
it("finds absolute webpack.config.js files", function () {
expect(resolve('foo', file, absoluteSettings)).to.exist
.and.equal(path.join(__dirname, 'files', 'some', 'absolutely', 'goofy', 'path', 'foo.js'))
})
})
16 changes: 16 additions & 0 deletions resolvers/webpack/test/files/some/absolute.path.webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
var path = require('path')

module.exports = {
resolve: {
alias: {
'foo': path.join(__dirname, 'absolutely', 'goofy', 'path', 'foo.js'),
},
modulesDirectories: ['node_modules', 'bower_components'],
root: path.join(__dirname, 'src'),
},

externals: [
{ 'jquery': 'jQuery' },
'bootstrap',
],
}
Empty file.