Skip to content

Commit 340a40f

Browse files
author
Frank Schmid
committed
Add --no-build switch for invoke local to use already compiled output
1 parent 321dd88 commit 340a40f

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,14 @@ class ServerlessWebpack {
112112
'before:invoke:local:invoke': () => BbPromise.bind(this)
113113
.then(() => {
114114
lib.webpack.isLocal = true;
115+
// --no-build override
116+
if (this.options.build === false) {
117+
this.skipCompile = true;
118+
}
119+
115120
return this.serverless.pluginManager.spawn('webpack:validate');
116121
})
117-
.then(() => this.serverless.pluginManager.spawn('webpack:compile'))
122+
.then(() => this.skipCompile ? BbPromise.resolve() : this.serverless.pluginManager.spawn('webpack:compile'))
118123
.then(this.prepareLocalInvoke),
119124

120125
'after:invoke:local:invoke': () => BbPromise.bind(this)
@@ -181,7 +186,7 @@ class ServerlessWebpack {
181186
lib.webpack.isLocal = true;
182187
})
183188
.then(this.prepareStepOfflineInvoke)
184-
.then(this.compile)
189+
.then(() => this.serverless.pluginManager.spawn('webpack:compile')),
185190
};
186191
}
187192
}

lib/validate.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,15 @@ module.exports = {
143143
this.webpackConfig.output.path = path.join(this.serverless.config.servicePath, this.options.out);
144144
}
145145

146+
if (this.skipCompile) {
147+
this.serverless.cli.log('Skipping build and using existing compiled output');
148+
if (!fse.pathExistsSync(this.webpackConfig.output.path)) {
149+
return BbPromise.reject(new this.serverless.classes
150+
.Error('No compiled output found'));
151+
}
152+
this.keepOutputDirectory = true;
153+
}
154+
146155
if (!this.keepOutputDirectory) {
147156
this.options.verbose && this.serverless.cli.log(`Removing ${this.webpackConfig.output.path}`);
148157
fse.removeSync(this.webpackConfig.output.path);

0 commit comments

Comments
 (0)