Skip to content

Commit c4e5cf4

Browse files
committed
serverless offline hook
1 parent 47cc936 commit c4e5cf4

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/index.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ class ServerlessReact {
127127
progress = DEFAULT_PROGRESS;
128128

129129
serverless: Serverless;
130+
serverlessConfig: ServerlessConfig;
130131
service: ServerlessService;
131132
pluginConfig: PluginConfig;
132133
configuration: {
@@ -141,6 +142,7 @@ class ServerlessReact {
141142
constructor(serverless: Serverless, protected options?: Options) {
142143
this.serverless = serverless;
143144
this.service = serverless.service;
145+
this.serverlessConfig = serverless.config;
144146
this.pluginConfig =
145147
(this.service.custom && this.service.custom[PLUGIN_NAME]) || {};
146148

@@ -197,23 +199,24 @@ class ServerlessReact {
197199
"react:build": async () => {
198200
console.log("!!!! react:build");
199201
},
202+
"before:offline:start:init": async () => {
203+
this.log.verbose("before:offline:start:init");
204+
await this.build();
205+
},
200206
};
201207
}
202208

203-
build = async (
204-
serverlessConfig: ServerlessConfig,
205-
pluginConfig: PluginConfig
206-
): Promise<void> => {
209+
build = async (): Promise<void> => {
207210
const webpackConfig = path.join(
208-
serverlessConfig.servicePath,
209-
pluginConfig.webpackConfig ||
211+
this.serverlessConfig.servicePath,
212+
this.pluginConfig.webpackConfig ||
210213
"node_modules/react-scripts/webpack.config.js"
211214
);
212215

213216
const configFactory = (await import(webpackConfig)).default;
214217
const config: Configuration = configFactory("production");
215218

216-
config.entry = pluginConfig.entryPoint || config.entry;
219+
config.entry = this.pluginConfig.entryPoint || config.entry;
217220

218221
const compiler = webpack(config);
219222

0 commit comments

Comments
 (0)