DefinitelyTyped/webpack/webpack.d.ts
2015-10-11 14:41:32 +09:00

360 lines
14 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Type definitions for webpack 1.12.2
// Project: https://github.com/webpack/webpack
// Definitions by: Qubo <https://github.com/tkqubo>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
declare module "webpack" {
namespace webpack {
interface Configuration {
entry?: string|Entry;
output?: Output;
module?: Module;
plugins?: (Plugin|Function)[];
}
interface Entry {
[name: string]: string|string[];
}
interface Output {
path?: string;
filename?: string;
chunkFilename?: string;
publicPath?: string;
}
interface Module {
loaders?: Loader[];
}
interface Loader {
test: RegExp;
loader?: string;
loaders?: string[];
query?: {
[name: string]: any;
}
}
interface Plugin { }
interface Webpack {
/**
* optimize namespace
*/
optimize: Optimize;
/**
* dependencies namespace
*/
dependencies: Dependencies;
/**
* Replace resources that matches resourceRegExp with newResource.
* If newResource is relative, it is resolve relative to the previous resource.
* If newResource is a function, it is expected to overwrite the request attribute of the supplied object.
*/
NormalModuleReplacementPlugin: NormalModuleReplacementPluginStatic;
/**
* Replaces the default resource, recursive flag or regExp generated by parsing with newContentResource,
* newContentRecursive resp. newContextRegExp if the resource (directory) matches resourceRegExp.
* If newContentResource is relative, it is resolve relative to the previous resource.
* If newContentResource is a function, it is expected to overwrite the request attribute of the supplied object.
*/
ContextReplacementPlugin: ContextReplacementPluginStatic;
/**
* Dont generate modules for requests matching the provided RegExp.
*/
IgnorePlugin: IgnorePluginStatic;
/**
* A request for a normal module, which is resolved and built even before a require to it occurs.
* This can boost performance. Try to profile the build first to determine clever prefetching points.
*/
PrefetchPlugin: PrefetchPluginStatic;
/**
* Apply a plugin (or array of plugins) to one or more resolvers (as specified in types).
*/
ResolverPlugin: ResolverPluginStatic;
/**
* Adds a banner to the top of each generated chunk.
*/
BannerPlugin: BannerPluginStatic;
/**
* Define free variables. Useful for having development builds with debug logging or adding global constants.
*/
DefinePlugin: DefinePluginStatic;
/**
* Automatically loaded modules.
* Module (value) is loaded when the identifier (key) is used as free variable in a module.
* The identifier is filled with the exports of the loaded module.
*/
ProvidePlugin: ProvidePluginStatic;
/**
* Adds SourceMaps for assets.
*/
SourceMapDevToolPlugin: SourceMapDevToolPluginStatic;
/**
* Enables Hot Module Replacement. (This requires records data if not in dev-server mode, recordsPath)
* Generates Hot Update Chunks of each chunk in the records.
* It also enables the API and makes __webpack_hash__ available in the bundle.
*/
HotModuleReplacementPlugin: HotModuleReplacementPluginStatic;
/**
* Adds useful free vars to the bundle.
*/
ExtendedAPIPlugin: ExtendedAPIPluginStatic;
/**
* When there are errors while compiling this plugin skips the emitting phase (and recording phase),
* so there are no assets emitted that include errors. The emitted flag in the stats is false for all assets.
*/
NoErrorsPlugin: NoErrorsPluginStatic;
/**
* Does not watch specified files matching provided paths or RegExps.
*/
WatchIgnorePlugin: WatchIgnorePluginStatic;
}
interface Optimize {
/**
* Search for equal or similar files and deduplicate them in the output.
* This comes with some overhead for the entry chunk, but can reduce file size effectively.
* This is experimental and may crash, because of some missing implementations. (Report an issue)
*/
DedupePlugin: optimize.DedupePluginStatic;
/**
* Limit the chunk count to a defined value. Chunks are merged until it fits.
*/
LimitChunkCountPlugin: optimize.LimitChunkCountPluginStatic;
/**
* Merge small chunks that are lower than this min size (in chars). Size is approximated.
*/
MinChunkSizePlugin: optimize.MinChunkSizePluginStatic;
/**
* Assign the module and chunk ids by occurrence count. Ids that are used often get lower (shorter) ids.
* This make ids predictable, reduces to total file size and is recommended.
*/
OccurenceOrderPlugin: optimize.OccurenceOrderPluginStatic;
/**
* Minimize all JavaScript output of chunks. Loaders are switched into minimizing mode.
* You can pass an object containing UglifyJs options.
*/
UglifyJsPlugin: optimize.UglifyJsPluginStatic;
CommonsChunkPlugin: optimize.CommonsChunkPluginStatic;
/**
* A plugin for a more aggressive chunk merging strategy.
* Even similar chunks are merged if the total size is reduced enough.
* As an option modules that are not common in these chunks can be moved up the chunk tree to the parents.
*/
AggressiveMergingPlugin: optimize.AggressiveMergingPluginStatic;
}
interface Dependencies {
/**
* Support Labeled Modules.
*/
LabeledModulesPlugin: dependencies.LabeledModulesPluginStatic;
}
interface DirectoryDescriptionFilePluginStatic {
new(file: string, files: string[]): Plugin;
}
interface NormalModuleReplacementPluginStatic {
new(resourceRegExp: any, newResource: any): Plugin;
}
interface ContextReplacementPluginStatic {
new(resourceRegExp: any, newContentResource?: any, newContentRecursive?: any, newContentRegExp?: any): Plugin
}
interface IgnorePluginStatic {
new(requestRegExp: any, contextRegExp?: any): Plugin;
}
interface PrefetchPluginStatic {
new(context: any, request: any): Plugin;
new(request: any): Plugin;
}
interface ResolverPluginStatic {
new(plugins: Plugin[], files?: string[]): Plugin;
DirectoryDescriptionFilePlugin: DirectoryDescriptionFilePluginStatic;
/**
* This plugin will append a path to the module directory to find a match,
* which can be useful if you have a module which has an incorrect “main” entry in its package.json/bower.json etc (e.g. "main": "Gruntfile.js").
* You can use this plugin as a special case to load the correct file for this module. Example:
*/
FileAppendPlugin: FileAppendPluginStatic;
}
interface FileAppendPluginStatic {
new(files: string[]): Plugin;
}
interface BannerPluginStatic {
new(banner: any, options: any): Plugin;
}
interface DefinePluginStatic {
new(definitions: any): Plugin;
}
interface ProvidePluginStatic {
new(definitions: any): Plugin;
}
interface SourceMapDevToolPluginStatic {
new(options: any): Plugin;
}
interface HotModuleReplacementPluginStatic {
new(): Plugin;
}
interface ExtendedAPIPluginStatic {
new(): Plugin;
}
interface NoErrorsPluginStatic {
new(): Plugin;
}
interface WatchIgnorePluginStatic {
new(paths: RegExp[]): Plugin;
}
namespace optimize {
interface DedupePluginStatic {
new(): Plugin;
}
interface LimitChunkCountPluginStatic {
new(options: any): Plugin
}
interface MinChunkSizePluginStatic {
new(options: any): Plugin;
}
interface OccurenceOrderPluginStatic {
new(preferEntry: boolean): Plugin;
}
interface UglifyJsPluginStatic {
new(options?: any): Plugin;
}
interface CommonsChunkPluginStatic {
new(chunkName: string, filenames?: string|string[]): Plugin;
new(options?: any): Plugin;
}
interface AggressiveMergingPluginStatic {
new(options: any): Plugin;
}
}
namespace dependencies {
interface LabeledModulesPluginStatic {
new(): Plugin;
}
}
}
var webpack: webpack.Webpack;
//export default webpack;
export = webpack;
}
/**
* Webpack module API - variables and global functions available inside modules
*/
declare namespace __WebpackModuleApi {
interface RequireContext {
keys(): string[];
<T>(id: string): T;
resolve(id: string): string;
}
interface RequireFunction {
/**
* Returns the exports from a dependency. The call is sync. No request to the server is fired. The compiler ensures that the dependency is available.
*/
<T>(path: string): T;
/**
* Behaves similar to require.ensure, but the callback is called with the exports of each dependency in the paths array. There is no option to provide a chunk name.
*/
(paths: string[], callback: (...modules: any[]) => void): void;
/**
* Download additional dependencies on demand. The paths array lists modules that should be available. When they are, callback is called. If the callback is a function expression, dependencies in that source part are extracted and also loaded on demand. A single request is fired to the server, except if all modules are already available.
*
* This creates a chunk. The chunk can be named. If a chunk with this name already exists, the dependencies are merged into that chunk and that chunk is used.
*/
ensure: (paths: string[], callback: (require: <T>(path: string) => T) => void) => void;
context: (path: string, deep?: boolean, filter?: RegExp) => RequireContext;
/**
* Returns the module id of a dependency. The call is sync. No request to the server is fired. The compiler ensures that the dependency is available.
*
* The module id is a number in webpack (in contrast to node.js where it is a string, the filename).
*/
resolve(path: string): number;
/**
* Like require.resolve, but doesnt include the module into the bundle. Its a weak dependency.
*/
resolveWeak(path: string): number;
/**
* Ensures that the dependency is available, but dont execute it. This can be use for optimizing the position of a module in the chunks.
*/
include(path: string): void;
/**
* Multiple requires to the same module result in only one module execution and only one export. Therefore a cache in the runtime exists. Removing values from this cache cause new module execution and a new export. This is only needed in rare cases (for compatibility!).
*/
cache: {
[id: string]: any;
}
}
}
declare var require: __WebpackModuleApi.RequireFunction;
/**
* The resource query of the current module.
*
* e.g. __resourceQuery === "?test" // Inside "file.js?test"
*/
declare var __resourceQuery: string;
/**
* Equals the config options output.publicPath.
*/
declare var __webpack_public_path__: string;
/**
* The raw require function. This expression isnt parsed by the Parser for dependencies.
*/
declare var __webpack_require__: any;
/**
* The internal chunk loading function
*
* @param chunkId The id for the chunk to load.
* @param callback A callback function called once the chunk is loaded.
*/
declare var __webpack_chunk_load__: (chunkId: any, callback: (require: (id: string) => any) => void) => void;
/**
* Access to the internal object of all modules.
*/
declare var __webpack_modules__: any[];
/**
* Access to the hash of the compilation.
*
* Only available with the HotModuleReplacementPlugin or the ExtendedAPIPlugin
*/
declare var __webpack_hash__: any;
/**
* Generates a require function that is not parsed by webpack. Can be used to do cool stuff with a global require function if available.
*/
declare var __non_webpack_require__: any;
/**
* Equals the config option debug
*/
declare var DEBUG: boolean;