Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support webpack configs that export a function #533

Merged
merged 1 commit into from
Sep 13, 2016
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
4 changes: 4 additions & 0 deletions resolvers/webpack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ exports.resolve = function (source, file, settings) {
webpackConfig = {}
}

if( typeof webpackConfig === 'function' ) {
webpackConfig = webpackConfig()
}

if (webpackConfig && webpackConfig.default) {
log('Using ES6 module "default" key instead of module.exports.')
webpackConfig = webpackConfig.default
Expand Down
36 changes: 36 additions & 0 deletions resolvers/webpack/test/files/webpack.function.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
var path = require('path')
var pluginsTest = require('webpack-resolver-plugin-test')

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

externals: [
{ 'jquery': 'jQuery' },
'bootstrap',
function (context, request, callback) {
if (request === 'underscore') {
return callback(null, 'underscore')
}
callback()
},
],

plugins: [
new pluginsTest.ResolverPlugin([
new pluginsTest.SimpleResolver(
path.join(__dirname, 'some', 'bar', 'bar.js'),
path.join(__dirname, 'some', 'bar')
),
]),
],
}
}
9 changes: 9 additions & 0 deletions resolvers/webpack/test/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,13 @@ describe("root", function () {
.property('path')
.to.equal(path.join(__dirname, 'files', 'bower_components', 'typeahead.js'))
})
it("supports definition as a function", function () {
expect(resolve('main-module', file, { config: "webpack.function.config.js" }))
.property('path')
.to.equal(path.join(__dirname, 'files', 'src', 'main-module.js'))
expect(resolve('typeahead', file, { config: "webpack.function.config.js" }))
.property('path')
.to.equal(path.join(__dirname, 'files', 'bower_components', 'typeahead.js'))
})

})