mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
[webpack-serve] update to version 2.0.0 (#27173)
* [webpack-serve] create a new subfolder with the v1 * [webpack-serve] update to version 2.0.0 * [webpack-serve] add the correct path mapping for the v1
This commit is contained in:
parent
7f9d41cfbb
commit
ba3048433e
162
types/webpack-serve/index.d.ts
vendored
162
types/webpack-serve/index.d.ts
vendored
@ -1,4 +1,4 @@
|
||||
// Type definitions for webpack-serve 1.0
|
||||
// Type definitions for webpack-serve 2.0
|
||||
// Project: https://github.com/webpack-contrib/webpack-serve
|
||||
// Definitions by: Ryan Clark <https://github.com/rynclark>
|
||||
// Jokcy <https://github.com/Jokcy>
|
||||
@ -13,85 +13,107 @@ import * as webpack from 'webpack';
|
||||
import * as webpackDevMiddleware from 'webpack-dev-middleware';
|
||||
import * as webpackHotClient from 'webpack-hot-client';
|
||||
import * as https from 'https';
|
||||
|
||||
export = WebpackServe;
|
||||
import * as net from 'net';
|
||||
|
||||
declare module 'webpack' {
|
||||
interface Configuration {
|
||||
serve?: WebpackServe.Options;
|
||||
}
|
||||
interface Configuration {
|
||||
serve?: WebpackServe.Options;
|
||||
}
|
||||
}
|
||||
|
||||
declare function WebpackServe(options: WebpackServe.Options): Promise<WebpackServe.Instance>;
|
||||
declare function WebpackServe(argv: object, options: WebpackServe.Options): Promise<WebpackServe.Result>;
|
||||
|
||||
declare namespace WebpackServe {
|
||||
interface WebpackServeOpen {
|
||||
/** Name of the browser to open */
|
||||
app?: string;
|
||||
/** Path on the server to open */
|
||||
path?: string;
|
||||
}
|
||||
interface Result {
|
||||
/** An instance of a Koa application, extended with a server property, and stop method, which is used to programatically stop the server */
|
||||
app: InitializedKoa;
|
||||
|
||||
interface WebpackServeMiddleware {
|
||||
/** Function to call to add koa-static */
|
||||
content: () => koa.Middleware;
|
||||
/** Function to call to add the webpack-dev-middleware */
|
||||
webpack: () => webpackDevMiddleware.WebpackDevMiddleware;
|
||||
}
|
||||
/** A function which binds a serve event-name to a function */
|
||||
on<K extends keyof EventMap>(type: K, callback: (args: EventMap[K]) => void): void;
|
||||
|
||||
interface Instance {
|
||||
/** Subscriber function for events */
|
||||
on(event: 'build-started', listener: (args: { compiler: webpack.Compiler }) => void): this;
|
||||
on(event: 'build-finished', listener: (args: { compiler: webpack.Compiler, stats: webpack.Stats }) => void): this;
|
||||
on(event: 'compiler-error' | 'compiler-warning', listener: (args: { compiler: webpack.Compiler, stats: any }) => void): this;
|
||||
on(event: 'listening', listener: (args: { server: koa, options: NormalisedOptions }) => void): this;
|
||||
/** Access to a frozen copy of the internal options object used by the module. */
|
||||
options: InitializedOptions;
|
||||
}
|
||||
|
||||
/** Close webpack-serve */
|
||||
close: () => void;
|
||||
}
|
||||
interface Options {
|
||||
/** Addon to webpack-serve that allows access to the Koa server instance */
|
||||
add?: (app: InitializedKoa, middleware: Middleware, options: Options) => void;
|
||||
|
||||
interface ListenersObject {
|
||||
'build-started': (args: { compiler: webpack.Compiler }) => void;
|
||||
'build-finished': (args: { compiler: webpack.Compiler, stats: webpack.Stats }) => void;
|
||||
'compiler-error': (args: { compiler: webpack.Compiler, stats: any }) => void;
|
||||
'compiler-warning': (args: { compiler: webpack.Compiler, stats: any }) => void;
|
||||
'listening': (args: { server: koa, options: NormalisedOptions }) => void;
|
||||
}
|
||||
/** Custom instance of a webpack compiler */
|
||||
compiler?: webpack.Compiler;
|
||||
|
||||
interface Options {
|
||||
/** Addon to webpack-serve that allows access to the Koa server instance */
|
||||
add?: (app: koa, middleware: WebpackServeMiddleware, options: Options) => void;
|
||||
/** Copy the server URL to the clipboard when the server is started */
|
||||
clipboard?: boolean;
|
||||
/** Custom instance of a webpack compiler */
|
||||
compiler?: webpack.Compiler;
|
||||
/** Webpack configuration for creating a new webpack compiler instance */
|
||||
config?: webpack.Configuration;
|
||||
/** A path or array of paths where content will be served from */
|
||||
content?: string | string[];
|
||||
/** Options for webpack-dev-middleware */
|
||||
dev?: webpackDevMiddleware.Options;
|
||||
/** The host the server will listen on */
|
||||
host?: string;
|
||||
/** Options for webpack-hot-client */
|
||||
hot?: webpackHotClient.Options | boolean;
|
||||
/** Enable HTTP2 support */
|
||||
http2?: boolean;
|
||||
/** Configuration object for the server to use HTTPS */
|
||||
https?: https.ServerOptions;
|
||||
/** Level of information for webpack-serve to output */
|
||||
logLevel?: 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'silent';
|
||||
/** Prepend timestamp to each log line */
|
||||
logTime?: boolean;
|
||||
/** Object of subscribers to webpack-serve bus events */
|
||||
on?: ListenersObject;
|
||||
/** Open the browser when started */
|
||||
open?: WebpackServeOpen | boolean;
|
||||
/** Port that the server listens on */
|
||||
port?: number;
|
||||
}
|
||||
/** Webpack configuration for creating a new webpack compiler instance */
|
||||
config?: webpack.Configuration;
|
||||
|
||||
interface NormalisedOptions extends Options {
|
||||
protocol: 'http' | 'https';
|
||||
}
|
||||
/** A path or array of paths where content will be served from */
|
||||
content?: string | string[];
|
||||
|
||||
/** Copy the server URL to the clipboard when the server is started */
|
||||
clipboard?: boolean;
|
||||
|
||||
/** Options for webpack-dev-middleware */
|
||||
devMiddleware?: webpackDevMiddleware.Options;
|
||||
|
||||
/** The host the server will listen on */
|
||||
host?: string;
|
||||
|
||||
/** Options for webpack-hot-client */
|
||||
hotClient?: webpackHotClient.Options | boolean;
|
||||
|
||||
/** Enable HTTP2 support */
|
||||
http2?: boolean;
|
||||
|
||||
/** Configuration object for the server to use HTTPS */
|
||||
https?: https.ServerOptions;
|
||||
|
||||
/** Level of information for webpack-serve to output */
|
||||
logLevel?: 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'silent';
|
||||
|
||||
/** Prepend timestamp to each log line */
|
||||
logTime?: boolean;
|
||||
|
||||
/** Object of subscribers to webpack-serve bus events */
|
||||
on?: OnOptions;
|
||||
|
||||
/** Open the browser when started */
|
||||
open?: OpenOptions | boolean;
|
||||
|
||||
/** Port that the server listens on */
|
||||
port?: number;
|
||||
}
|
||||
|
||||
interface OpenOptions {
|
||||
/** Name of the browser to open */
|
||||
app?: string;
|
||||
/** Path on the server to open */
|
||||
path?: string;
|
||||
}
|
||||
|
||||
type OnOptions = { [K in keyof EventMap]?: (args: EventMap[K]) => void };
|
||||
|
||||
interface InitializedKoa extends koa {
|
||||
server: net.Server;
|
||||
stop: () => void;
|
||||
}
|
||||
|
||||
interface InitializedOptions extends Options {
|
||||
protocol: 'http' | 'https';
|
||||
}
|
||||
|
||||
interface Middleware {
|
||||
/** Function to call to add koa-static */
|
||||
content: () => void;
|
||||
/** Function to call to add the webpack-dev-middleware */
|
||||
webpack: () => void;
|
||||
}
|
||||
|
||||
interface EventMap {
|
||||
'build-started': { compiler: webpack.Compiler };
|
||||
'build-finished': { compiler: webpack.Compiler; stats: webpack.Stats };
|
||||
'compiler-error': { compiler: webpack.Compiler; stats: any };
|
||||
'compiler-warning': { compiler: webpack.Compiler; stats: any };
|
||||
listening: { server: net.Server; options: InitializedOptions };
|
||||
}
|
||||
}
|
||||
|
||||
export = WebpackServe;
|
||||
|
||||
@ -1,23 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"webpack-serve-tests.ts"
|
||||
]
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"webpack-serve-tests.ts"
|
||||
]
|
||||
}
|
||||
|
||||
97
types/webpack-serve/v1/index.d.ts
vendored
Normal file
97
types/webpack-serve/v1/index.d.ts
vendored
Normal file
@ -0,0 +1,97 @@
|
||||
// Type definitions for webpack-serve 1.0
|
||||
// Project: https://github.com/webpack-contrib/webpack-serve
|
||||
// Definitions by: Ryan Clark <https://github.com/rynclark>
|
||||
// Jokcy <https://github.com/Jokcy>
|
||||
// ZSkycat <https://github.com/ZSkycat>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
import * as koa from 'koa';
|
||||
import * as webpack from 'webpack';
|
||||
import * as webpackDevMiddleware from 'webpack-dev-middleware';
|
||||
import * as webpackHotClient from 'webpack-hot-client';
|
||||
import * as https from 'https';
|
||||
|
||||
export = WebpackServe;
|
||||
|
||||
declare module 'webpack' {
|
||||
interface Configuration {
|
||||
serve?: WebpackServe.Options;
|
||||
}
|
||||
}
|
||||
|
||||
declare function WebpackServe(options: WebpackServe.Options): Promise<WebpackServe.Instance>;
|
||||
|
||||
declare namespace WebpackServe {
|
||||
interface WebpackServeOpen {
|
||||
/** Name of the browser to open */
|
||||
app?: string;
|
||||
/** Path on the server to open */
|
||||
path?: string;
|
||||
}
|
||||
|
||||
interface WebpackServeMiddleware {
|
||||
/** Function to call to add koa-static */
|
||||
content: () => koa.Middleware;
|
||||
/** Function to call to add the webpack-dev-middleware */
|
||||
webpack: () => webpackDevMiddleware.WebpackDevMiddleware;
|
||||
}
|
||||
|
||||
interface Instance {
|
||||
/** Subscriber function for events */
|
||||
on(event: 'build-started', listener: (args: { compiler: webpack.Compiler }) => void): this;
|
||||
on(event: 'build-finished', listener: (args: { compiler: webpack.Compiler, stats: webpack.Stats }) => void): this;
|
||||
on(event: 'compiler-error' | 'compiler-warning', listener: (args: { compiler: webpack.Compiler, stats: any }) => void): this;
|
||||
on(event: 'listening', listener: (args: { server: koa, options: NormalisedOptions }) => void): this;
|
||||
|
||||
/** Close webpack-serve */
|
||||
close: () => void;
|
||||
}
|
||||
|
||||
interface ListenersObject {
|
||||
'build-started': (args: { compiler: webpack.Compiler }) => void;
|
||||
'build-finished': (args: { compiler: webpack.Compiler, stats: webpack.Stats }) => void;
|
||||
'compiler-error': (args: { compiler: webpack.Compiler, stats: any }) => void;
|
||||
'compiler-warning': (args: { compiler: webpack.Compiler, stats: any }) => void;
|
||||
'listening': (args: { server: koa, options: NormalisedOptions }) => void;
|
||||
}
|
||||
|
||||
interface Options {
|
||||
/** Addon to webpack-serve that allows access to the Koa server instance */
|
||||
add?: (app: koa, middleware: WebpackServeMiddleware, options: Options) => void;
|
||||
/** Copy the server URL to the clipboard when the server is started */
|
||||
clipboard?: boolean;
|
||||
/** Custom instance of a webpack compiler */
|
||||
compiler?: webpack.Compiler;
|
||||
/** Webpack configuration for creating a new webpack compiler instance */
|
||||
config?: webpack.Configuration;
|
||||
/** A path or array of paths where content will be served from */
|
||||
content?: string | string[];
|
||||
/** Options for webpack-dev-middleware */
|
||||
dev?: webpackDevMiddleware.Options;
|
||||
/** The host the server will listen on */
|
||||
host?: string;
|
||||
/** Options for webpack-hot-client */
|
||||
hot?: webpackHotClient.Options | boolean;
|
||||
/** Enable HTTP2 support */
|
||||
http2?: boolean;
|
||||
/** Configuration object for the server to use HTTPS */
|
||||
https?: https.ServerOptions;
|
||||
/** Level of information for webpack-serve to output */
|
||||
logLevel?: 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'silent';
|
||||
/** Prepend timestamp to each log line */
|
||||
logTime?: boolean;
|
||||
/** Object of subscribers to webpack-serve bus events */
|
||||
on?: ListenersObject;
|
||||
/** Open the browser when started */
|
||||
open?: WebpackServeOpen | boolean;
|
||||
/** Port that the server listens on */
|
||||
port?: number;
|
||||
}
|
||||
|
||||
interface NormalisedOptions extends Options {
|
||||
protocol: 'http' | 'https';
|
||||
}
|
||||
}
|
||||
26
types/webpack-serve/v1/tsconfig.json
Normal file
26
types/webpack-serve/v1/tsconfig.json
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../../",
|
||||
"typeRoots": [
|
||||
"../../"
|
||||
],
|
||||
"paths": {
|
||||
"webpack-serve": ["webpack-serve/v1"]
|
||||
},
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"webpack-serve-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/webpack-serve/v1/tslint.json
Normal file
1
types/webpack-serve/v1/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
64
types/webpack-serve/v1/webpack-serve-tests.ts
Normal file
64
types/webpack-serve/v1/webpack-serve-tests.ts
Normal file
@ -0,0 +1,64 @@
|
||||
import webpack = require('webpack');
|
||||
import serve = require('webpack-serve');
|
||||
|
||||
const config: webpack.Configuration = {
|
||||
mode: 'development',
|
||||
entry: ['index.js'], // when use compiler entry must be array or object
|
||||
};
|
||||
|
||||
const serveConfig = {
|
||||
http2: true,
|
||||
dev: {
|
||||
publicPath: '/',
|
||||
logLevel: 'info'
|
||||
},
|
||||
host: 'localhost'
|
||||
};
|
||||
|
||||
const compiler = webpack(config);
|
||||
|
||||
const server = serve({
|
||||
compiler,
|
||||
...serveConfig
|
||||
});
|
||||
|
||||
server
|
||||
.then((server) => {
|
||||
server.on('listening', () => {
|
||||
server.close();
|
||||
});
|
||||
});
|
||||
|
||||
const config2: webpack.Configuration = {
|
||||
...config,
|
||||
serve: {
|
||||
...serveConfig,
|
||||
port: 8888,
|
||||
hot: {
|
||||
port: 8889
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
const server2 = serve({
|
||||
config: config2
|
||||
});
|
||||
|
||||
server2
|
||||
.then((server) => {
|
||||
server.on('listening', () => {
|
||||
server.close();
|
||||
});
|
||||
});
|
||||
|
||||
const server3 = serve({
|
||||
logLevel: 'silent',
|
||||
config: config2
|
||||
});
|
||||
|
||||
server3
|
||||
.then((server) => {
|
||||
server.on('listening', () => {
|
||||
server.close();
|
||||
});
|
||||
});
|
||||
@ -1,64 +1,49 @@
|
||||
import webpack = require('webpack');
|
||||
import serve = require('webpack-serve');
|
||||
|
||||
const config: webpack.Configuration = {
|
||||
mode: 'development',
|
||||
entry: ['index.js'], // when use compiler entry must be array or object
|
||||
const webpackConfig: webpack.Configuration = {
|
||||
entry: { index: './index.js' },
|
||||
};
|
||||
|
||||
const serveConfig = {
|
||||
http2: true,
|
||||
dev: {
|
||||
publicPath: '/',
|
||||
logLevel: 'info'
|
||||
},
|
||||
host: 'localhost'
|
||||
const webpackCompiler = webpack(webpackConfig);
|
||||
|
||||
const serveConfig: serve.Options = {
|
||||
add: (app, middleware, options) => {
|
||||
middleware.content();
|
||||
middleware.webpack();
|
||||
},
|
||||
compiler: webpackCompiler,
|
||||
config: webpackConfig,
|
||||
content: './webroot',
|
||||
clipboard: true,
|
||||
devMiddleware: {
|
||||
logLevel: 'warn',
|
||||
publicPath: '/',
|
||||
},
|
||||
host: 'localhost',
|
||||
hotClient: {
|
||||
logLevel: 'warn',
|
||||
allEntries: true,
|
||||
},
|
||||
http2: true,
|
||||
https: {},
|
||||
logLevel: 'info',
|
||||
logTime: false,
|
||||
on: {
|
||||
'build-finished': args => {
|
||||
console.log(args.stats.toString());
|
||||
},
|
||||
},
|
||||
open: {
|
||||
path: '/index.html',
|
||||
},
|
||||
port: 65080,
|
||||
};
|
||||
|
||||
const compiler = webpack(config);
|
||||
const promise = serve({}, serveConfig);
|
||||
|
||||
const server = serve({
|
||||
compiler,
|
||||
...serveConfig
|
||||
});
|
||||
|
||||
server
|
||||
.then((server) => {
|
||||
server.on('listening', () => {
|
||||
server.close();
|
||||
promise.then(result => {
|
||||
result.on('compiler-error', args => {
|
||||
console.log(args.stats);
|
||||
});
|
||||
});
|
||||
|
||||
const config2: webpack.Configuration = {
|
||||
...config,
|
||||
serve: {
|
||||
...serveConfig,
|
||||
port: 8888,
|
||||
hot: {
|
||||
port: 8889
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
const server2 = serve({
|
||||
config: config2
|
||||
});
|
||||
|
||||
server2
|
||||
.then((server) => {
|
||||
server.on('listening', () => {
|
||||
server.close();
|
||||
});
|
||||
});
|
||||
|
||||
const server3 = serve({
|
||||
logLevel: 'silent',
|
||||
config: config2
|
||||
});
|
||||
|
||||
server3
|
||||
.then((server) => {
|
||||
server.on('listening', () => {
|
||||
server.close();
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user