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

Extends the --no-build option to serverless offline start #770

Merged
merged 10 commits into from
May 6, 2021
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,8 @@ e.g. a mounted volume in a Docker container, you can enable polling with the
`--webpack-use-polling=<time in ms>` option. If you omit the value, it defaults
to 3000 ms.

If you don't want the plugin to build when using `serverless-offline`, select the `--no-build` option.

#### Custom paths

If you do not use the default path and override it in your Webpack configuration,
Expand Down
12 changes: 10 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,25 @@ 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.wpwatch),
.then(() => (this.skipCompile ? BbPromise.resolve() : this.wpwatch())),

'before:offline:start:init': () =>
BbPromise.bind(this)
.tap(() => {
lib.webpack.isLocal = true;
// --no-build override
if (this.options.build === false) {
this.skipCompile = true;
}
})
.then(this.prepareOfflineInvoke)
.then(this.wpwatch),
.then(() => (this.skipCompile ? BbPromise.resolve() : this.wpwatch())),

'before:step-functions-offline:start': () =>
BbPromise.bind(this)
Expand Down
25 changes: 25 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ describe('ServerlessWebpack', () => {
});

it('should skip compile if requested', () => {
slsw.options.build = false;
slsw.skipCompile = true;
return expect(slsw.hooks['before:invoke:local:invoke']()).to.be.fulfilled.then(() => {
expect(slsw.serverless.pluginManager.spawn).to.have.been.calledOnce;
Expand Down Expand Up @@ -401,26 +402,50 @@ describe('ServerlessWebpack', () => {
name: 'before:offline:start',
test: () => {
it('should prepare offline', () => {
slsw.skipCompile = false;
slsw.options.build = true;
return expect(slsw.hooks['before:offline:start']()).to.be.fulfilled.then(() => {
expect(ServerlessWebpack.lib.webpack.isLocal).to.be.true;
expect(slsw.prepareOfflineInvoke).to.have.been.calledOnce;
expect(slsw.wpwatch).to.have.been.calledOnce;
return null;
});
});
it('should skip compiling when requested', () => {
slsw.skipCompile = true;
slsw.options.build = false;
return expect(slsw.hooks['before:offline:start']()).to.be.fulfilled.then(() => {
expect(ServerlessWebpack.lib.webpack.isLocal).to.be.true;
expect(slsw.prepareOfflineInvoke).to.have.been.calledOnce;
expect(slsw.wpwatch).to.not.have.been.called;
return null;
});
});
}
},
{
name: 'before:offline:start:init',
test: () => {
it('should prepare offline', () => {
slsw.skipCompile = false;
slsw.options.build = true;
return expect(slsw.hooks['before:offline:start:init']()).to.be.fulfilled.then(() => {
expect(ServerlessWebpack.lib.webpack.isLocal).to.be.true;
expect(slsw.prepareOfflineInvoke).to.have.been.calledOnce;
expect(slsw.wpwatch).to.have.been.calledOnce;
return null;
});
});
it('should skip compiling when requested', () => {
slsw.skipCompile = false;
slsw.options.build = false;
return expect(slsw.hooks['before:offline:start:init']()).to.be.fulfilled.then(() => {
expect(ServerlessWebpack.lib.webpack.isLocal).to.be.true;
expect(slsw.prepareOfflineInvoke).to.have.been.calledOnce;
expect(slsw.wpwatch).to.not.have.been.called;
return null;
});
});
}
},
{
Expand Down