webpack-dev-service 0.7.2 → 0.8.0
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.
- package/README.md +7 -10
- package/client/cjs/client.cjs +1 -1
- package/client/cjs/events.cjs +1 -1
- package/client/cjs/hot.cjs +1 -1
- package/client/cjs/index.cjs +1 -1
- package/client/cjs/main.cjs +1 -1
- package/client/cjs/ui/overlay.cjs +1 -1
- package/client/cjs/ui/progress.cjs +1 -1
- package/client/cjs/ui/utils.cjs +1 -1
- package/client/esm/client.js +1 -1
- package/client/esm/events.js +1 -1
- package/client/esm/hot.js +1 -1
- package/client/esm/index.js +1 -1
- package/client/esm/main.js +1 -1
- package/client/esm/ui/overlay.js +1 -1
- package/client/esm/ui/progress.js +1 -1
- package/client/esm/ui/utils.js +1 -1
- package/global.d.ts +2 -0
- package/package.json +13 -6
- package/server/cjs/dev/Files.cjs +394 -0
- package/server/cjs/dev/index.cjs +62 -0
- package/server/cjs/dev/middleware.cjs +70 -0
- package/server/cjs/dev/utils/boundary.cjs +42 -0
- package/server/cjs/dev/utils/common.cjs +98 -0
- package/server/cjs/dev/utils/compose.cjs +58 -0
- package/server/cjs/dev/utils/getPaths.cjs +65 -0
- package/server/cjs/dev/utils/http.cjs +69 -0
- package/server/cjs/dev/utils/ready.cjs +26 -0
- package/server/cjs/dev/utils/setupHooks.cjs +95 -0
- package/server/cjs/dev/utils/setupOutputFileSystem.cjs +64 -0
- package/server/cjs/dev/utils/setupWatching.cjs +43 -0
- package/server/cjs/dev/utils/setupWriteToDisk.cjs +62 -0
- package/server/cjs/{hot.cjs → hot/Socket.cjs} +6 -20
- package/server/cjs/hot/index.cjs +36 -0
- package/server/cjs/index.cjs +11 -15
- package/server/esm/dev/Files.js +384 -0
- package/server/esm/dev/index.js +60 -0
- package/server/esm/dev/middleware.js +68 -0
- package/server/esm/dev/utils/boundary.js +40 -0
- package/server/esm/dev/utils/common.js +98 -0
- package/server/esm/dev/utils/compose.js +56 -0
- package/server/esm/dev/utils/getPaths.js +63 -0
- package/server/esm/dev/utils/http.js +65 -0
- package/server/esm/dev/utils/ready.js +24 -0
- package/server/esm/dev/utils/setupHooks.js +87 -0
- package/server/esm/dev/utils/setupOutputFileSystem.js +62 -0
- package/server/esm/dev/utils/setupWatching.js +41 -0
- package/server/esm/dev/utils/setupWriteToDisk.js +60 -0
- package/server/esm/{hot.js → hot/Socket.js} +6 -20
- package/server/esm/hot/index.js +34 -0
- package/server/esm/index.js +11 -9
- package/types/server/dev/Files.d.ts +83 -0
- package/types/server/dev/index.d.ts +8 -0
- package/types/server/dev/interface.d.ts +46 -0
- package/types/server/dev/middleware.d.ts +6 -0
- package/types/server/dev/utils/boundary.d.ts +8 -0
- package/types/server/dev/utils/common.d.ts +44 -0
- package/types/server/dev/utils/compose.d.ts +18 -0
- package/types/server/dev/utils/getPaths.d.ts +10 -0
- package/types/server/dev/utils/http.d.ts +22 -0
- package/types/server/dev/utils/ready.d.ts +5 -0
- package/types/server/dev/utils/setupHooks.d.ts +5 -0
- package/types/server/dev/utils/setupOutputFileSystem.d.ts +5 -0
- package/types/server/dev/utils/setupWatching.d.ts +5 -0
- package/types/server/dev/utils/setupWriteToDisk.d.ts +5 -0
- package/types/server/hot/Socket.d.ts +27 -0
- package/types/server/{hot.d.ts → hot/index.d.ts} +7 -10
- package/types/server/index.d.ts +4 -4
- package/server/cjs/dev.cjs +0 -50
- package/server/esm/dev.js +0 -42
- package/types/server/dev.d.ts +0 -17
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package webpack-dev-service
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 0.
|
|
4
|
+
* @version 0.8.0
|
|
5
5
|
* @author nuintun <nuintun@qq.com>
|
|
6
6
|
* @description A koa 2 middleware for webpack development and hot reloading.
|
|
7
7
|
* @see https://github.com/nuintun/webpack-dev-service#readme
|
|
@@ -11,11 +11,12 @@ import WebSocket, { WebSocketServer } from 'ws';
|
|
|
11
11
|
import webpack from 'webpack';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
* @module
|
|
14
|
+
* @module Socket
|
|
15
15
|
*/
|
|
16
16
|
const WEBSOCKET_RE = /^websocket$/i;
|
|
17
|
+
const { toString } = Object.prototype;
|
|
17
18
|
function isObject(value) {
|
|
18
|
-
return
|
|
19
|
+
return toString.call(value) === '[object Object]';
|
|
19
20
|
}
|
|
20
21
|
function resolveStatsOptions(compiler) {
|
|
21
22
|
const options = {
|
|
@@ -72,7 +73,7 @@ function isUpgradable(context, detector) {
|
|
|
72
73
|
function hasProblems(problems) {
|
|
73
74
|
return !!problems && problems.length > 0;
|
|
74
75
|
}
|
|
75
|
-
class
|
|
76
|
+
class Socket {
|
|
76
77
|
constructor(compiler, options) {
|
|
77
78
|
this.name = 'webpack-hot-middleware';
|
|
78
79
|
this.compiler = compiler;
|
|
@@ -183,20 +184,5 @@ class HotServer {
|
|
|
183
184
|
}
|
|
184
185
|
}
|
|
185
186
|
}
|
|
186
|
-
function hot(compiler, options = {}) {
|
|
187
|
-
const server = new HotServer(compiler, options);
|
|
188
|
-
const hotMiddleware = async (context, next) => {
|
|
189
|
-
if (!server.upgrade(context)) {
|
|
190
|
-
await next();
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
hotMiddleware.clients = () => {
|
|
194
|
-
return server.clients();
|
|
195
|
-
};
|
|
196
|
-
hotMiddleware.broadcast = (clients, action, payload) => {
|
|
197
|
-
server.broadcast(clients, action, payload);
|
|
198
|
-
};
|
|
199
|
-
return hotMiddleware;
|
|
200
|
-
}
|
|
201
187
|
|
|
202
|
-
export {
|
|
188
|
+
export { Socket };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @package webpack-dev-service
|
|
3
|
+
* @license MIT
|
|
4
|
+
* @version 0.8.0
|
|
5
|
+
* @author nuintun <nuintun@qq.com>
|
|
6
|
+
* @description A koa 2 middleware for webpack development and hot reloading.
|
|
7
|
+
* @see https://github.com/nuintun/webpack-dev-service#readme
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { Socket } from './Socket.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @module index
|
|
14
|
+
*/
|
|
15
|
+
function hot(compiler, options = {}) {
|
|
16
|
+
const socket = new Socket(compiler, options);
|
|
17
|
+
return Object.assign(
|
|
18
|
+
async (ctx, next) => {
|
|
19
|
+
if (!socket.upgrade(ctx)) {
|
|
20
|
+
await next();
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
clients() {
|
|
25
|
+
return socket.clients();
|
|
26
|
+
},
|
|
27
|
+
broadcast(clients, action, payload) {
|
|
28
|
+
socket.broadcast(clients, action, payload);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { hot };
|
package/server/esm/index.js
CHANGED
|
@@ -1,25 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package webpack-dev-service
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 0.
|
|
4
|
+
* @version 0.8.0
|
|
5
5
|
* @author nuintun <nuintun@qq.com>
|
|
6
6
|
* @description A koa 2 middleware for webpack development and hot reloading.
|
|
7
7
|
* @see https://github.com/nuintun/webpack-dev-service#readme
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import compose from '
|
|
11
|
-
import dev from './dev.js';
|
|
12
|
-
import hot from './hot.js';
|
|
10
|
+
import { compose } from './dev/utils/compose.js';
|
|
11
|
+
import { dev } from './dev/index.js';
|
|
12
|
+
import { hot } from './hot/index.js';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* @module index
|
|
16
16
|
*/
|
|
17
17
|
function server(compiler, options = {}) {
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
const devMiddleware = dev(compiler, options);
|
|
19
|
+
if (options.hot === false) {
|
|
20
|
+
return devMiddleware;
|
|
21
|
+
}
|
|
22
|
+
const hotMiddleware = hot(compiler, options.hot);
|
|
23
|
+
const middleware = compose(devMiddleware, hotMiddleware);
|
|
24
|
+
return Object.assign(middleware, devMiddleware, hotMiddleware);
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
export { server as default };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Files
|
|
3
|
+
*/
|
|
4
|
+
import { Context } from 'koa';
|
|
5
|
+
import { FilesOptions } from './interface';
|
|
6
|
+
/**
|
|
7
|
+
* @class Files
|
|
8
|
+
*/
|
|
9
|
+
export default class Files {
|
|
10
|
+
private root;
|
|
11
|
+
private options;
|
|
12
|
+
/**
|
|
13
|
+
* @constructor
|
|
14
|
+
* @description Create files service.
|
|
15
|
+
* @param root Files service root.
|
|
16
|
+
* @param options Files service options.
|
|
17
|
+
*/
|
|
18
|
+
constructor(root: string, options: FilesOptions);
|
|
19
|
+
/**
|
|
20
|
+
* @private
|
|
21
|
+
* @method isConditionalGET
|
|
22
|
+
* @description Check if request is conditional GET.
|
|
23
|
+
* @param context Koa context.
|
|
24
|
+
*/
|
|
25
|
+
private isConditionalGET;
|
|
26
|
+
/**
|
|
27
|
+
* @private
|
|
28
|
+
* @method isPreconditionFailure
|
|
29
|
+
* @description Check if request precondition failure.
|
|
30
|
+
* @param context Koa context.
|
|
31
|
+
*/
|
|
32
|
+
private isPreconditionFailure;
|
|
33
|
+
/**
|
|
34
|
+
* @private
|
|
35
|
+
* @method isRangeFresh
|
|
36
|
+
* @description Check if request range fresh.
|
|
37
|
+
* @param context Koa context.
|
|
38
|
+
*/
|
|
39
|
+
private isRangeFresh;
|
|
40
|
+
/**
|
|
41
|
+
* @private
|
|
42
|
+
* @method parseRange
|
|
43
|
+
* @description Parse range.
|
|
44
|
+
* @param context Koa context.
|
|
45
|
+
* @param stats File stats.
|
|
46
|
+
*/
|
|
47
|
+
private parseRange;
|
|
48
|
+
/**
|
|
49
|
+
* @private
|
|
50
|
+
* @method setupHeaders
|
|
51
|
+
* @description Setup headers
|
|
52
|
+
* @param context Koa context
|
|
53
|
+
* @param path File path
|
|
54
|
+
* @param stats File stats
|
|
55
|
+
*/
|
|
56
|
+
private setupHeaders;
|
|
57
|
+
/**
|
|
58
|
+
* @private
|
|
59
|
+
* @method readTo
|
|
60
|
+
* @description Read file.
|
|
61
|
+
* @param stream Destination stream.
|
|
62
|
+
* @param path File path.
|
|
63
|
+
* @param range Read range.
|
|
64
|
+
* @param end Is destory destination stream after read.
|
|
65
|
+
*/
|
|
66
|
+
private readTo;
|
|
67
|
+
/**
|
|
68
|
+
* @private
|
|
69
|
+
* @method send
|
|
70
|
+
* @description Send file.
|
|
71
|
+
* @param context Koa context.
|
|
72
|
+
* @param path File path.
|
|
73
|
+
* @param ranges Read ranges.
|
|
74
|
+
*/
|
|
75
|
+
private send;
|
|
76
|
+
/**
|
|
77
|
+
* @public
|
|
78
|
+
* @method response
|
|
79
|
+
* @description Response to koa context.
|
|
80
|
+
* @param context Koa context.
|
|
81
|
+
*/
|
|
82
|
+
response(context: Context): Promise<boolean>;
|
|
83
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module index
|
|
3
|
+
*/
|
|
4
|
+
import { Middleware } from 'koa';
|
|
5
|
+
import { Compiler } from 'webpack';
|
|
6
|
+
import { AdditionalMethods, Options } from './interface';
|
|
7
|
+
export { AdditionalMethods, Options };
|
|
8
|
+
export declare function dev(compiler: Compiler, options?: Options): Middleware & AdditionalMethods;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module interface
|
|
3
|
+
*/
|
|
4
|
+
/// <reference types="node" />
|
|
5
|
+
import { createReadStream, Stats as FileStats } from 'fs';
|
|
6
|
+
import { Compiler, Configuration, MultiCompiler, MultiStats, Stats, Watching } from 'webpack';
|
|
7
|
+
type IOutputFileSystem = NonNullable<Compiler['outputFileSystem']>;
|
|
8
|
+
interface HeaderFunction {
|
|
9
|
+
(path: string, stats: FileStats): Record<string, string | string[]>;
|
|
10
|
+
}
|
|
11
|
+
export interface OutputFileSystem extends IOutputFileSystem {
|
|
12
|
+
createReadStream: typeof createReadStream;
|
|
13
|
+
}
|
|
14
|
+
export type Callback = (stats: Stats | MultiStats | null) => void;
|
|
15
|
+
export interface FilesOptions {
|
|
16
|
+
etag?: boolean;
|
|
17
|
+
fs: OutputFileSystem;
|
|
18
|
+
cacheControl?: string;
|
|
19
|
+
acceptRanges?: boolean;
|
|
20
|
+
lastModified?: boolean;
|
|
21
|
+
headers?: HeaderFunction | Record<string, string | string[]>;
|
|
22
|
+
}
|
|
23
|
+
export interface Options extends Omit<FilesOptions, 'fs'> {
|
|
24
|
+
stats?: Configuration['stats'];
|
|
25
|
+
outputFileSystem?: OutputFileSystem;
|
|
26
|
+
writeToDisk?: boolean | ((targetPath: string) => boolean);
|
|
27
|
+
}
|
|
28
|
+
export interface Context {
|
|
29
|
+
state: boolean;
|
|
30
|
+
options: Options;
|
|
31
|
+
callbacks: Callback[];
|
|
32
|
+
stats: Stats | MultiStats | null;
|
|
33
|
+
compiler: Compiler | MultiCompiler;
|
|
34
|
+
outputFileSystem: OutputFileSystem;
|
|
35
|
+
logger: ReturnType<Compiler['getInfrastructureLogger']>;
|
|
36
|
+
watching: Watching | ReturnType<MultiCompiler['watch']>;
|
|
37
|
+
}
|
|
38
|
+
export interface AdditionalMethods {
|
|
39
|
+
isReady(): boolean;
|
|
40
|
+
logger: Context['logger'];
|
|
41
|
+
ready(callback: Callback): void;
|
|
42
|
+
invalidate(callback: Callback): void;
|
|
43
|
+
close(callback: (error?: Error | null) => void): void;
|
|
44
|
+
}
|
|
45
|
+
export type InitialContext = Optional<Context, 'watching' | 'outputFileSystem'>;
|
|
46
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module common
|
|
3
|
+
*/
|
|
4
|
+
/// <reference types="node" />
|
|
5
|
+
import { Stats } from 'fs';
|
|
6
|
+
import { Compiler, MultiCompiler } from 'webpack';
|
|
7
|
+
import { OutputFileSystem } from '../../../server/dev/interface';
|
|
8
|
+
export declare const PLUGIN_NAME = 'webpack-dev-service';
|
|
9
|
+
/**
|
|
10
|
+
* @function unixify
|
|
11
|
+
* @description Convert path to unix style.
|
|
12
|
+
* @param path The path to convert.
|
|
13
|
+
*/
|
|
14
|
+
export declare function unixify(path: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* @function decodeURI
|
|
17
|
+
* @description Decode URI component.
|
|
18
|
+
* @param URI The URI to decode.
|
|
19
|
+
*/
|
|
20
|
+
export declare function decodeURI(URI: string): string | -1;
|
|
21
|
+
/**
|
|
22
|
+
* @function hasTrailingSlash
|
|
23
|
+
* @description Check if path has trailing slash.
|
|
24
|
+
* @param path The path to check.
|
|
25
|
+
*/
|
|
26
|
+
export declare function hasTrailingSlash(path: string): boolean;
|
|
27
|
+
export declare function isString(value: unknown): value is string;
|
|
28
|
+
export declare function isBoolean(value: unknown): value is boolean;
|
|
29
|
+
export declare function isFunction(value: unknown): value is Function;
|
|
30
|
+
/**
|
|
31
|
+
* @function isOutRoot
|
|
32
|
+
* @description Check if path is out of root.
|
|
33
|
+
* @param path The path to check.
|
|
34
|
+
* @param root The root path.
|
|
35
|
+
*/
|
|
36
|
+
export declare function isOutRoot(path: string, root: string): boolean;
|
|
37
|
+
export declare function getCompilers(compiler: Compiler | MultiCompiler): Compiler[];
|
|
38
|
+
/**
|
|
39
|
+
* @function fstat
|
|
40
|
+
* @description Get file stats.
|
|
41
|
+
* @param path The file path.
|
|
42
|
+
*/
|
|
43
|
+
export declare function fstat(fs: OutputFileSystem, path: string): Promise<Stats | undefined>;
|
|
44
|
+
export declare function isMultiCompilerMode(compiler: Compiler | MultiCompiler): compiler is MultiCompiler;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module compose
|
|
3
|
+
*/
|
|
4
|
+
export interface Next {
|
|
5
|
+
(): Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
export interface Composed<C> {
|
|
8
|
+
(context: C, next?: Next): Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
export interface Middleware<C> {
|
|
11
|
+
(context: C, next: Next): Promise<void> | void;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* @function compose
|
|
15
|
+
* @description 生成融合中间件
|
|
16
|
+
* @param middlewares 中间件数组
|
|
17
|
+
*/
|
|
18
|
+
export declare function compose<C>(...middlewares: Middleware<C>[]): Composed<C>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @method http
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* @function parseTokens
|
|
6
|
+
* @description Parse HTTP tokens.
|
|
7
|
+
* @param value The tokens value string.
|
|
8
|
+
*/
|
|
9
|
+
export declare function parseTokens(value: string): string[];
|
|
10
|
+
/**
|
|
11
|
+
* @function isETag
|
|
12
|
+
* @description Check if etag is valid.
|
|
13
|
+
* @param value The value to check.
|
|
14
|
+
*/
|
|
15
|
+
export declare function isETag(value: string): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* @function isETagFresh
|
|
18
|
+
* @description Check if etag is fresh.
|
|
19
|
+
* @param match The match value.
|
|
20
|
+
* @param etag The etag value.
|
|
21
|
+
*/
|
|
22
|
+
export declare function isETagFresh(match: string, etag: string): boolean;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Socket
|
|
3
|
+
*/
|
|
4
|
+
import { Context } from 'koa';
|
|
5
|
+
import WebSocket from 'ws';
|
|
6
|
+
import { Compiler, StatsCompilation } from 'webpack';
|
|
7
|
+
export interface Options {
|
|
8
|
+
hmr?: boolean;
|
|
9
|
+
path?: string;
|
|
10
|
+
progress?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare class Socket {
|
|
13
|
+
private stats;
|
|
14
|
+
private readonly compiler;
|
|
15
|
+
private readonly server;
|
|
16
|
+
private readonly options;
|
|
17
|
+
private readonly name;
|
|
18
|
+
private readonly logger;
|
|
19
|
+
constructor(compiler: Compiler, options: Options);
|
|
20
|
+
setupWss(): void;
|
|
21
|
+
setupHooks(): void;
|
|
22
|
+
setupPlugins(): void;
|
|
23
|
+
clients(): Set<WebSocket>;
|
|
24
|
+
upgrade(context: Context): boolean;
|
|
25
|
+
broadcast<T>(clients: Set<WebSocket> | WebSocket[], action: string, payload: T): void;
|
|
26
|
+
broadcastStats(clients: Set<WebSocket> | WebSocket[], stats: StatsCompilation): void;
|
|
27
|
+
}
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @module
|
|
2
|
+
* @module index
|
|
3
3
|
*/
|
|
4
|
-
import { Middleware } from 'koa';
|
|
5
4
|
import WebSocket from 'ws';
|
|
5
|
+
import { Middleware } from 'koa';
|
|
6
6
|
import { Compiler } from 'webpack';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
progress?: boolean;
|
|
11
|
-
}
|
|
12
|
-
export type Instance = {
|
|
7
|
+
import { Options } from './Socket';
|
|
8
|
+
export { Options };
|
|
9
|
+
export interface AdditionalMethods {
|
|
13
10
|
clients(): Set<WebSocket>;
|
|
14
11
|
broadcast<T>(clients: Set<WebSocket> | WebSocket[], action: string, payload: T): void;
|
|
15
|
-
}
|
|
16
|
-
export
|
|
12
|
+
}
|
|
13
|
+
export declare function hot(compiler: Compiler, options?: Options): Middleware & AdditionalMethods;
|
package/types/server/index.d.ts
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { Middleware } from 'koa';
|
|
5
5
|
import { Compiler } from 'webpack';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
6
|
+
import { AdditionalMethods as DevMethods, Options as DevOptions } from './dev';
|
|
7
|
+
import { AdditionalMethods as HotMethods, Options as HotOptions } from './hot';
|
|
8
8
|
type DisableHotOptions = DevOptions & {
|
|
9
9
|
hot: false;
|
|
10
10
|
};
|
|
@@ -12,8 +12,8 @@ type EnableHotOptions = DevOptions & {
|
|
|
12
12
|
hot?: HotOptions;
|
|
13
13
|
};
|
|
14
14
|
export type Options = EnableHotOptions | DisableHotOptions;
|
|
15
|
-
export type DisableHotMiddleware = Middleware &
|
|
16
|
-
export type EnableHotMiddleware = DisableHotMiddleware &
|
|
15
|
+
export type DisableHotMiddleware = Middleware & DevMethods;
|
|
16
|
+
export type EnableHotMiddleware = DisableHotMiddleware & HotMethods;
|
|
17
17
|
/**
|
|
18
18
|
* @function server
|
|
19
19
|
* @description Create koa dev server middleware.
|
package/server/cjs/dev.cjs
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @package webpack-dev-service
|
|
3
|
-
* @license MIT
|
|
4
|
-
* @version 0.7.2
|
|
5
|
-
* @author nuintun <nuintun@qq.com>
|
|
6
|
-
* @description A koa 2 middleware for webpack development and hot reloading.
|
|
7
|
-
* @see https://github.com/nuintun/webpack-dev-service#readme
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
'use strict';
|
|
11
|
-
|
|
12
|
-
const webpackDevMiddleware = require('webpack-dev-middleware');
|
|
13
|
-
|
|
14
|
-
function _interopDefault(e) {
|
|
15
|
-
return e && e.__esModule ? e : { default: e };
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const webpackDevMiddleware__default = /*#__PURE__*/ _interopDefault(webpackDevMiddleware);
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @module dev
|
|
22
|
-
*/
|
|
23
|
-
function dev(compiler, options) {
|
|
24
|
-
const middleware = webpackDevMiddleware__default.default(compiler, options);
|
|
25
|
-
const devMiddleware = async (context, next) => {
|
|
26
|
-
context.remove('Content-Type');
|
|
27
|
-
await middleware(
|
|
28
|
-
context.req,
|
|
29
|
-
{
|
|
30
|
-
locals: context.state,
|
|
31
|
-
send(body) {
|
|
32
|
-
context.body = body;
|
|
33
|
-
},
|
|
34
|
-
status(statusCode) {
|
|
35
|
-
context.status = statusCode;
|
|
36
|
-
},
|
|
37
|
-
set(field, value) {
|
|
38
|
-
context.response.set(field, value);
|
|
39
|
-
},
|
|
40
|
-
get(field) {
|
|
41
|
-
return context.response.get(field);
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
next
|
|
45
|
-
);
|
|
46
|
-
};
|
|
47
|
-
return Object.assign(devMiddleware, middleware);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
module.exports = dev;
|
package/server/esm/dev.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @package webpack-dev-service
|
|
3
|
-
* @license MIT
|
|
4
|
-
* @version 0.7.2
|
|
5
|
-
* @author nuintun <nuintun@qq.com>
|
|
6
|
-
* @description A koa 2 middleware for webpack development and hot reloading.
|
|
7
|
-
* @see https://github.com/nuintun/webpack-dev-service#readme
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import webpackDevMiddleware from 'webpack-dev-middleware';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* @module dev
|
|
14
|
-
*/
|
|
15
|
-
function dev(compiler, options) {
|
|
16
|
-
const middleware = webpackDevMiddleware(compiler, options);
|
|
17
|
-
const devMiddleware = async (context, next) => {
|
|
18
|
-
context.remove('Content-Type');
|
|
19
|
-
await middleware(
|
|
20
|
-
context.req,
|
|
21
|
-
{
|
|
22
|
-
locals: context.state,
|
|
23
|
-
send(body) {
|
|
24
|
-
context.body = body;
|
|
25
|
-
},
|
|
26
|
-
status(statusCode) {
|
|
27
|
-
context.status = statusCode;
|
|
28
|
-
},
|
|
29
|
-
set(field, value) {
|
|
30
|
-
context.response.set(field, value);
|
|
31
|
-
},
|
|
32
|
-
get(field) {
|
|
33
|
-
return context.response.get(field);
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
next
|
|
37
|
-
);
|
|
38
|
-
};
|
|
39
|
-
return Object.assign(devMiddleware, middleware);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export { dev as default };
|
package/types/server/dev.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module dev
|
|
3
|
-
*/
|
|
4
|
-
/// <reference types="node" />
|
|
5
|
-
import { AdditionalMethods, ExtendedServerResponse, IncomingMessage, Options as DevOptions } from 'webpack-dev-middleware';
|
|
6
|
-
import { Middleware } from 'koa';
|
|
7
|
-
import { Compiler } from 'webpack';
|
|
8
|
-
import { ServerResponse } from 'http';
|
|
9
|
-
export interface OutgoingMessage extends ServerResponse, ExtendedServerResponse {
|
|
10
|
-
send(body: any): void;
|
|
11
|
-
get(field: string): string;
|
|
12
|
-
status(statusCode: number): void;
|
|
13
|
-
set(field: string, value: string): void;
|
|
14
|
-
}
|
|
15
|
-
export type Options = DevOptions<IncomingMessage, OutgoingMessage>;
|
|
16
|
-
export type Instance = AdditionalMethods<IncomingMessage, OutgoingMessage>;
|
|
17
|
-
export default function dev(compiler: Compiler, options: Options): Middleware & Instance;
|