This repository was archived by the owner on Aug 7, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathbefore-watch.js
35 lines (32 loc) · 1.5 KB
/
before-watch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const { getWebpackProcesses, runWebpackCompiler, stopWebpackCompiler } = require("./compiler");
const { addListener } = require("./utils");
module.exports = function ($logger, $liveSyncService, $devicesService, hookArgs) {
if (hookArgs.config) {
const appFilesUpdaterOptions = hookArgs.config.appFilesUpdaterOptions;
if (appFilesUpdaterOptions.bundle) {
addListener($liveSyncService, "liveSyncStopped", () => {
const webpackProcesses = getWebpackProcesses();
Object.keys(webpackProcesses).forEach(platform => {
const devices = $devicesService.getDevicesForPlatform(platform);
if (!devices || !devices.length) {
stopWebpackCompiler(platform);
}
});
});
addListener(process, "exit", stopWebpackCompiler);
const platforms = hookArgs.config.platforms;
return Promise.all(platforms.map(platform => {
const env = hookArgs.config.env || {};
env.hmr = appFilesUpdaterOptions.useHotModuleReload;
const config = {
env,
platform,
bundle: appFilesUpdaterOptions.bundle,
release: appFilesUpdaterOptions.release,
watch: true
};
return runWebpackCompiler(config, hookArgs.projectData, $logger, $liveSyncService, hookArgs);
}));
}
}
}