From a41272778c9e8c0f9c930e33df6e50713f87388f Mon Sep 17 00:00:00 2001 From: tkqubo Date: Sat, 2 Jan 2016 15:50:51 +0900 Subject: [PATCH 1/3] feat: add typings --- webpack/webpack.d.ts | 93 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 90 insertions(+), 3 deletions(-) diff --git a/webpack/webpack.d.ts b/webpack/webpack.d.ts index 3889446b2..7846239dc 100644 --- a/webpack/webpack.d.ts +++ b/webpack/webpack.d.ts @@ -6,10 +6,27 @@ declare module "webpack" { namespace webpack { interface Configuration { + context?: string; entry?: string|string[]|Entry; devtool?: string; output?: Output; module?: Module; + resolve?: Resolve; + resolveLoader?: ResolveLoader; + externals?: ExternalsElement|ExternalsElement[]; + target?: string; + bail?: boolean; + profile?: boolean; + cache?: boolean|any; + watch?: boolean; + watchOptions?: WatchOptions; + debug?: boolean; + devServer?: any; // TODO: Type this + node?: Node; + amd?: { [moduleName: string]: boolean }; + recordsPath?: string; + recordsInputPath?: string; + recordsOutputPath?: string; plugins?: (Plugin|Function)[]; } @@ -21,17 +38,87 @@ declare module "webpack" { path?: string; filename?: string; chunkFilename?: string; + sourceMapFilename?: string; + devtoolModuleFilenameTemplate?: string; + devtoolFallbackModuleFilenameTemplate?: string; + devtoolLineToLine?: boolean; + hotUpdateChunkFilename?: string; + hotUpdateMainFilename?: string; publicPath?: string; + jsonpFunction?: string; + hotUpdateFunction?: string; + pathinfo?: boolean; + library?: boolean; + libraryTarget?: string; + umdNamedDefine?: boolean; + sourcePrefix?: string; + crossOriginLoading?: string|boolean; } interface Module { loaders?: Loader[]; + preLoaders?: Loader[]; + postLoaders?: Loader[]; + noParse?: RegExp|RegExp[]; + unknownContextRequest?: string; + unknownContextRecursive?: boolean; + unknownContextRegExp?: RegExp; + unknownContextCritical?: boolean; + exprContextRequest?: string; + exprContextRegExp?: RegExp; + exprContextRecursive?: boolean; + exprContextCritical?: boolean; + wrappedContextRegExp?: RegExp; + wrappedContextRecursive?: boolean; + wrappedContextCritical?: boolean; } + interface Resolve { + alias: { [key: string]: string; }; + root?: string|string[]; + modulesDirectories?: string[]; + fallback?: string|string[]; + extensions?: string[]; + packageMains?: (string|string[])[]; + packageAlias?: (string|string[])[]; + unsafeCache?: RegExp|RegExp[]|boolean; + } + + interface ResolveLoader extends Resolve { + moduleTemplates?: string[]; + } + + type ExternalsElement = string|RegExp|ExternalsObjectElement|ExternalsFunctionElement; + + interface ExternalsObjectElement { + [key: string]: boolean|string; + } + + interface ExternalsFunctionElement { + (context: any, request: any, callback: (error: any, result: any) => void): any; + } + + interface WatchOptions { + aggregateTimeout?: number; + poll?: boolean|number; + } + + interface Node { + console?: boolean; + global?: boolean; + process?: boolean; + Buffer?: boolean; + __filename?: boolean|string; + __dirname?: boolean|string; + [nodeBuiltin: string]: boolean|string; + } + + type LoaderCondition = string|RegExp|((absPath: string) => boolean); + interface Loader { - exclude?: string[]; - include?: string[]; - test: RegExp; + exclude?: LoaderCondition|LoaderCondition[]; + include?: LoaderCondition|LoaderCondition[]; + test: LoaderCondition|LoaderCondition[]; loader?: string; loaders?: string[]; query?: { From 8a951cf86555290bc23001ce02ae4e9a2eae0428 Mon Sep 17 00:00:00 2001 From: tkqubo Date: Sat, 2 Jan 2016 16:22:37 +0900 Subject: [PATCH 2/3] chore: update webpack version --- webpack/webpack.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webpack/webpack.d.ts b/webpack/webpack.d.ts index 7846239dc..9e0ae9e7f 100644 --- a/webpack/webpack.d.ts +++ b/webpack/webpack.d.ts @@ -1,4 +1,4 @@ -// Type definitions for webpack 1.12.2 +// Type definitions for webpack 1.12.9 // Project: https://github.com/webpack/webpack // Definitions by: Qubo // Definitions: https://github.com/borisyankov/DefinitelyTyped From 25c3427fd8957a334648449b436734490043f05a Mon Sep 17 00:00:00 2001 From: tkqubo Date: Sat, 2 Jan 2016 16:23:10 +0900 Subject: [PATCH 3/3] docs: add comments --- webpack/webpack.d.ts | 101 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/webpack/webpack.d.ts b/webpack/webpack.d.ts index 9e0ae9e7f..5bf5050b8 100644 --- a/webpack/webpack.d.ts +++ b/webpack/webpack.d.ts @@ -8,25 +8,56 @@ declare module "webpack" { interface Configuration { context?: string; entry?: string|string[]|Entry; + /** Choose a developer tool to enhance debugging. */ devtool?: string; + /** Options affecting the output. */ output?: Output; + /** Options affecting the normal modules (NormalModuleFactory) */ module?: Module; + /** Options affecting the resolving of modules. */ resolve?: Resolve; + /** Like resolve but for loaders. */ resolveLoader?: ResolveLoader; + /** + * Specify dependencies that shouldn’t be resolved by webpack, but should become dependencies of the resulting bundle. + * The kind of the dependency depends on output.libraryTarget. + */ externals?: ExternalsElement|ExternalsElement[]; + /** + *
    + *
  • "web" Compile for usage in a browser-like environment (default)
  • + *
  • "webworker" Compile as WebWorker
  • + *
  • "node" Compile for usage in a node.js-like environment (use require to load chunks)
  • + *
  • "async-node" Compile for usage in a node.js-like environment (use fs and vm to load chunks async)
  • + *
  • "node-webkit" Compile for usage in webkit, uses jsonp chunk loading but also supports builtin node.js modules plus require(“nw.gui”) (experimental)
  • + *
  • "atom" Compile for usage in electron (formerly known as atom-shell), supports require for modules necessary to run Electron.
  • + *
      + */ target?: string; + /** Report the first error as a hard error instead of tolerating it. */ bail?: boolean; + /** Capture timing information for each module. */ profile?: boolean; + /** Cache generated modules and chunks to improve performance for multiple incremental builds. */ cache?: boolean|any; + /** Enter watch mode, which rebuilds on file change. */ watch?: boolean; watchOptions?: WatchOptions; + /** Switch loaders to debug mode. */ debug?: boolean; + /** Can be used to configure the behaviour of webpack-dev-server when the webpack config is passed to webpack-dev-server CLI. */ devServer?: any; // TODO: Type this + /** Include polyfills or mocks for various node stuff */ node?: Node; + /** Set the value of require.amd and define.amd. */ amd?: { [moduleName: string]: boolean }; + /** Used for recordsInputPath and recordsOutputPath */ recordsPath?: string; + /** Load compiler state from a json file. */ recordsInputPath?: string; + /** Store compiler state to a json file. */ recordsOutputPath?: string; + /** Add additional plugins to the compiler. */ plugins?: (Plugin|Function)[]; } @@ -35,30 +66,67 @@ declare module "webpack" { } interface Output { + /** The output directory as absolute path (required). */ path?: string; + /** The filename of the entry chunk as relative path inside the output.path directory. */ filename?: string; + /** The filename of non-entry chunks as relative path inside the output.path directory. */ chunkFilename?: string; + /** The filename of the SourceMaps for the JavaScript files. They are inside the output.path directory. */ sourceMapFilename?: string; + /** Filename template string of function for the sources array in a generated SourceMap. */ devtoolModuleFilenameTemplate?: string; + /** Similar to output.devtoolModuleFilenameTemplate, but used in the case of duplicate module identifiers. */ devtoolFallbackModuleFilenameTemplate?: string; + /** + * Enable line to line mapped mode for all/specified modules. + * Line to line mapped mode uses a simple SourceMap where each line of the generated source is mapped to the same line of the original source. + * It’s a performance optimization. Only use it if your performance need to be better and you are sure that input lines match which generated lines. + * true enables it for all modules (not recommended) + */ devtoolLineToLine?: boolean; + /** The filename of the Hot Update Chunks. They are inside the output.path directory. */ hotUpdateChunkFilename?: string; + /** The filename of the Hot Update Main File. It is inside the output.path directory. */ hotUpdateMainFilename?: string; + /** The output.path from the view of the Javascript / HTML page. */ publicPath?: string; + /** The JSONP function used by webpack for asnyc loading of chunks. */ jsonpFunction?: string; + /** The JSONP function used by webpack for async loading of hot update chunks. */ hotUpdateFunction?: string; + /** Include comments with information about the modules. */ pathinfo?: boolean; + /** If set, export the bundle as library. output.library is the name. */ library?: boolean; + /** + * Which format to export the library: + *
        + *
      • "var" - Export by setting a variable: var Library = xxx (default)
      • + *
      • "this" - Export by setting a property of this: this["Library"] = xxx
      • + *
      • "commonjs" - Export by setting a property of exports: exports["Library"] = xxx
      • + *
      • "commonjs2" - Export by setting module.exports: module.exports = xxx
      • + *
      • "amd" - Export to AMD (optionally named)
      • + *
      • "umd" - Export to AMD, CommonJS2 or as property in root
      • + *
      + */ libraryTarget?: string; + /** If output.libraryTarget is set to umd and output.library is set, setting this to true will name the AMD module. */ umdNamedDefine?: boolean; + /** Prefixes every line of the source in the bundle with this string. */ sourcePrefix?: string; + /** This option enables cross-origin loading of chunks. */ crossOriginLoading?: string|boolean; } interface Module { + /** A array of automatically applied loaders. */ loaders?: Loader[]; + /** A array of applied pre loaders. */ preLoaders?: Loader[]; + /** A array of applied post loaders. */ postLoaders?: Loader[]; + /** A RegExp or an array of RegExps. Don’t parse files matching. */ noParse?: RegExp|RegExp[]; unknownContextRequest?: string; unknownContextRecursive?: boolean; @@ -74,17 +142,43 @@ declare module "webpack" { } interface Resolve { + /** Replace modules by other modules or paths. */ alias: { [key: string]: string; }; + /** + * The directory (absolute path) that contains your modules. + * May also be an array of directories. + * This setting should be used to add individual directories to the search path. */ root?: string|string[]; + /** + * An array of directory names to be resolved to the current directory as well as its ancestors, and searched for modules. + * This functions similarly to how node finds “node_modules” directories. + * For example, if the value is ["mydir"], webpack will look in “./mydir”, “../mydir”, “../../mydir”, etc. + */ modulesDirectories?: string[]; + /** + * A directory (or array of directories absolute paths), + * in which webpack should look for modules that weren’t found in resolve.root or resolve.modulesDirectories. + */ fallback?: string|string[]; + /** + * An array of extensions that should be used to resolve modules. + * For example, in order to discover CoffeeScript files, your array should contain the string ".coffee". + */ extensions?: string[]; + /** Check these fields in the package.json for suitable files. */ packageMains?: (string|string[])[]; + /** Check this field in the package.json for an object. Key-value-pairs are threaded as aliasing according to this spec */ packageAlias?: (string|string[])[]; + /** + * Enable aggressive but unsafe caching for the resolving of a part of your files. + * Changes to cached paths may cause failure (in rare cases). An array of RegExps, only a RegExp or true (all files) is expected. + * If the resolved path matches, it’ll be cached. + */ unsafeCache?: RegExp|RegExp[]|boolean; } interface ResolveLoader extends Resolve { + /** It describes alternatives for the module name that are tried. */ moduleTemplates?: string[]; } @@ -99,7 +193,9 @@ declare module "webpack" { } interface WatchOptions { + /** Delay the rebuilt after the first change. Value is a time in ms. */ aggregateTimeout?: number; + /** true: use polling, number: use polling with specified interval */ poll?: boolean|number; } @@ -116,10 +212,15 @@ declare module "webpack" { type LoaderCondition = string|RegExp|((absPath: string) => boolean); interface Loader { + /** A condition that must not be met */ exclude?: LoaderCondition|LoaderCondition[]; + /** A condition that must be met */ include?: LoaderCondition|LoaderCondition[]; + /** A condition that must be met */ test: LoaderCondition|LoaderCondition[]; + /** A string of “!” separated loaders */ loader?: string; + /** A array of loaders as string */ loaders?: string[]; query?: { [name: string]: any;