diff --git a/lib/validate.js b/lib/validate.js index 8209ec8e2..cae04ed74 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -131,7 +131,8 @@ module.exports = { ); } try { - this.webpackConfig = require(webpackConfigFilePath); + const webpackConfig = require(webpackConfigFilePath); + this.webpackConfig = webpackConfig.default || webpackConfig; } catch (err) { this.serverless.cli.log(`Could not load webpack config '${webpackConfigFilePath}'`); return BbPromise.reject(err); diff --git a/tests/validate.test.js b/tests/validate.test.js index ee4210b99..839a44c55 100644 --- a/tests/validate.test.js +++ b/tests/validate.test.js @@ -271,6 +271,30 @@ describe('validate', () => { }); }); + it('should interop default when webpack config is exported as an ES6 module', () => { + const testConfig = 'testconfig'; + const testServicePath = 'testpath'; + const requiredPath = path.join(testServicePath, testConfig); + module.serverless.config.servicePath = testServicePath; + module.serverless.service.custom.webpack = testConfig; + serverless.utils.fileExistsSync = sinon.stub().returns(true); + const loadedConfig = { + default: { + entry: 'testentry' + } + }; + mockery.registerMock(requiredPath, loadedConfig); + return expect(module.validate()) + .to.fulfilled.then(() => { + expect(serverless.utils.fileExistsSync).to.have.been.calledWith(requiredPath); + expect(module.webpackConfig).to.eql(loadedConfig.default); + return null; + }) + .finally(() => { + mockery.deregisterMock(requiredPath); + }); + }); + it('should catch errors while loading a async webpack config from file if `custom.webpack` is a string', () => { const testConfig = 'testconfig'; const testServicePath = 'testpath';