Skip to content

Commit

Permalink
Merge pull request #770 from nponeccop/master
Browse files Browse the repository at this point in the history
Extends the --no-build option to serverless offline start
  • Loading branch information
j0k3r authored May 6, 2021
2 parents 540f600 + 2984e8c commit a846d28
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
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

0 comments on commit a846d28

Please sign in to comment.