@atls/webpack-start-server-plugin 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
3
1
|
import type { ChildProcess } from 'node:child_process';
|
|
4
2
|
import type { Writable } from 'node:stream';
|
|
5
3
|
import type webpack from 'webpack';
|
|
@@ -15,7 +13,7 @@ export declare class StartServerPlugin {
|
|
|
15
13
|
initialized: boolean;
|
|
16
14
|
logger: StartServerLogger;
|
|
17
15
|
constructor(options?: Partial<StartServerPluginOptions>);
|
|
18
|
-
apply
|
|
16
|
+
apply(compiler: webpack.Compiler): void;
|
|
19
17
|
private afterEmit;
|
|
20
18
|
private startServer;
|
|
21
19
|
private runWorker;
|
|
@@ -2,36 +2,38 @@ import { fork } from 'node:child_process';
|
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { StartServerLogger } from './start-server.logger.js';
|
|
4
4
|
export class StartServerPlugin {
|
|
5
|
+
options;
|
|
6
|
+
entryFile = null;
|
|
7
|
+
worker = null;
|
|
8
|
+
initialized = false;
|
|
9
|
+
logger;
|
|
5
10
|
constructor(options = {}) {
|
|
6
|
-
this.entryFile = null;
|
|
7
|
-
this.worker = null;
|
|
8
|
-
this.initialized = false;
|
|
9
|
-
this.apply = (compiler) => {
|
|
10
|
-
compiler.hooks.afterEmit.tapAsync({ name: 'StartServerPlugin' }, this.afterEmit);
|
|
11
|
-
};
|
|
12
|
-
this.afterEmit = (compilation, callback) => {
|
|
13
|
-
if (!this.initialized) {
|
|
14
|
-
this.initialized = true;
|
|
15
|
-
callback();
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
if (this.worker?.connected && this.worker.pid) {
|
|
19
|
-
process.kill(this.worker.pid);
|
|
20
|
-
}
|
|
21
|
-
this.startServer(compilation, callback);
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
this.startServer = (compilation, callback) => {
|
|
25
|
-
this.logger.info('Starting server...');
|
|
26
|
-
this.entryFile = join(compilation.compiler.options.output.path, 'index.js');
|
|
27
|
-
this.runWorker(this.entryFile, (worker) => {
|
|
28
|
-
this.worker = worker;
|
|
29
|
-
callback();
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
11
|
this.logger = new StartServerLogger(options);
|
|
33
12
|
this.options = options;
|
|
34
13
|
}
|
|
14
|
+
apply(compiler) {
|
|
15
|
+
compiler.hooks.afterEmit.tapAsync({ name: 'StartServerPlugin' }, this.afterEmit);
|
|
16
|
+
}
|
|
17
|
+
afterEmit = (compilation, callback) => {
|
|
18
|
+
if (!this.initialized) {
|
|
19
|
+
this.initialized = true;
|
|
20
|
+
callback();
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
if (this.worker?.connected && this.worker.pid) {
|
|
24
|
+
process.kill(this.worker.pid);
|
|
25
|
+
}
|
|
26
|
+
this.startServer(compilation, callback);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
startServer = (compilation, callback) => {
|
|
30
|
+
this.logger.info('Starting server...');
|
|
31
|
+
this.entryFile = join(compilation.compiler.options.output.path, 'index.js');
|
|
32
|
+
this.runWorker(this.entryFile, (worker) => {
|
|
33
|
+
this.worker = worker;
|
|
34
|
+
callback();
|
|
35
|
+
});
|
|
36
|
+
};
|
|
35
37
|
runWorker(entryFile, callback) {
|
|
36
38
|
const worker = fork(entryFile, [], {
|
|
37
39
|
silent: true,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atls/webpack-start-server-plugin",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"license": "BSD-3-Clause",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -21,10 +21,10 @@
|
|
|
21
21
|
"postpack": "rm -rf dist"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"webpack": "
|
|
24
|
+
"webpack": "5.97.1"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@types/node": "
|
|
27
|
+
"@types/node": "22.9.0"
|
|
28
28
|
},
|
|
29
29
|
"publishConfig": {
|
|
30
30
|
"access": "public",
|