diff --git a/README.md b/README.md index a603dc567e..6dceee56b1 100644 --- a/README.md +++ b/README.md @@ -662,6 +662,16 @@ On CI systems it is likely that you'll run multiple integration tests with `invo sequentially. To improve this, you can do one compile and run multiple invokes on the compiled output - it is not necessary to compile again before each and every invoke. +##### Using the CLI option `--no-build` + +```bash +$ serverless webpack +$ serverless invoke local --function --no-build +$ serverless invoke local --function --no-build +``` + +##### Using the parameter `noBuild` + ```yaml custom: webpack: diff --git a/index.js b/index.js index 35129994b5..cef8f3e8ac 100644 --- a/index.js +++ b/index.js @@ -97,6 +97,10 @@ class ServerlessWebpack { commands: { local: { options: { + 'no-build': { + usage: 'Skip Webpack compilation', + type: 'boolean' + }, watch: { usage: 'Flag to watch changes', type: 'boolean' @@ -217,6 +221,10 @@ class ServerlessWebpack { BbPromise.bind(this) .tap(() => { lib.webpack.isLocal = true; + // --no-build override + if (this.options.build === false) { + this.skipCompile = true; + } }) .then(this.prepareOfflineInvoke) .then(() => (this.skipCompile ? BbPromise.resolve() : this.wpwatch())), @@ -225,6 +233,10 @@ class ServerlessWebpack { BbPromise.bind(this) .tap(() => { lib.webpack.isLocal = true; + // --no-build override + if (this.options.build === false) { + this.skipCompile = true; + } }) .then(this.prepareOfflineInvoke) .then(() => (this.skipCompile ? BbPromise.resolve() : this.wpwatch())), diff --git a/lib/prepareOfflineInvoke.js b/lib/prepareOfflineInvoke.js index 06bcf85382..c3fa417c5e 100644 --- a/lib/prepareOfflineInvoke.js +++ b/lib/prepareOfflineInvoke.js @@ -10,7 +10,7 @@ const path = require('path'); module.exports = { prepareOfflineInvoke() { this.skipCompile = - _.get(this.serverless, 'service.custom.webpack.noBuild') === true || _.get(this.options, 'build') === false; + _.get(this.serverless, 'service.custom.webpack.noBuild') === true || _.get(this.options, 'no-build') === true; // Use service packaging for compile _.set(this.serverless, 'service.package.individually', false); diff --git a/lib/validate.js b/lib/validate.js index d4ae281296..1633f60b86 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -223,7 +223,7 @@ module.exports = { } this.skipCompile = - _.get(this.serverless, 'service.custom.webpack.noBuild') === true || _.get(this.options, 'build') === false; + _.get(this.serverless, 'service.custom.webpack.noBuild') === true || _.get(this.options, 'no-build') === true; // Skip compilation with --no-build or noBuild if (this.skipCompile) { diff --git a/tests/index.test.js b/tests/index.test.js index b8d261c389..43c7fc055d 100644 --- a/tests/index.test.js +++ b/tests/index.test.js @@ -418,7 +418,7 @@ describe('ServerlessWebpack', () => { }); }); it('should skip compiling when requested', () => { - slsw.skipCompile = true; + slsw.skipCompile = false; slsw.options.build = false; return expect(slsw.hooks['before:offline:start:init']()) .resolves.toBeUndefined() diff --git a/tests/validate.test.js b/tests/validate.test.js index b5f5d0451b..9e4857b06c 100644 --- a/tests/validate.test.js +++ b/tests/validate.test.js @@ -1188,7 +1188,7 @@ describe('validate', () => { }); describe('with skipped builds', () => { - it('should set `skipCompile` to true if `options.build` is false', () => { + it('should set `skipCompile` to true if `options.no-build` is true', () => { const testConfig = { entry: 'test', output: {} @@ -1197,7 +1197,7 @@ describe('validate', () => { module.serverless.config.servicePath = testServicePath; _.set(module.serverless.service, 'custom.webpack.config', testConfig); - module.options.build = false; + module.options['no-build'] = true; fsExtraMock.pathExistsSync.mockReturnValue(true); return module.validate().then(() => { @@ -1214,7 +1214,7 @@ describe('validate', () => { const testServicePath = 'testpath'; module.serverless.config.servicePath = testServicePath; _.set(module.serverless.service, 'custom.webpack.config', testConfig); - module.options.build = false; + module.options['no-build'] = true; fsExtraMock.pathExistsSync.mockReturnValue(true); return module.validate().then(() => { expect(module.keepOutputDirectory).toBe(true); @@ -1230,7 +1230,7 @@ describe('validate', () => { const testServicePath = 'testpath'; module.serverless.config.servicePath = testServicePath; _.set(module.serverless.service, 'custom.webpack.config', testConfig); - module.options.build = false; + module.options['no-build'] = true; fsExtraMock.pathExistsSync.mockReturnValue(false); return expect(module.validate()).rejects.toThrow(/No compiled output found/); });