From 9b593e264d25ac6351ce959bb06a4e5c1cdd613f Mon Sep 17 00:00:00 2001 From: Dennis George Date: Tue, 27 Feb 2018 13:43:11 -0600 Subject: [PATCH 1/9] updated for webpack 4.0 --- types/webpack/index.d.ts | 48 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/types/webpack/index.d.ts b/types/webpack/index.d.ts index d6102808b6..06483792cd 100644 --- a/types/webpack/index.d.ts +++ b/types/webpack/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for webpack 3.8 +// Type definitions for webpack 4.0 // Project: https://github.com/webpack/webpack // Definitions by: Qubo // Benjamin Lim @@ -35,6 +35,8 @@ declare function webpack(options: webpack.Configuration[]): webpack.MultiCompile declare namespace webpack { interface Configuration { + /** Specify which set of defaults to use. */ + mode?: "development" | "production"; /** Name of the configuration. Used when loading multiple configurations. */ name?: string; /** @@ -105,6 +107,9 @@ declare namespace webpack { performance?: Options.Performance; /** Limit the number of parallel processed modules. Can be used to fine tune performance or to get more reliable profiling results */ parallelism?: number; + + /** Optimization options */ + optimization?: Options.Optimization; } interface Entry { @@ -496,6 +501,47 @@ declare namespace webpack { } type Stats = Stats.ToStringOptions; type WatchOptions = ICompiler.WatchOptions; + + interface Optimization { + /** Modules are removed from chunks when they are already available in all parent chunk groups. + * This reduces asset size. Smaller assets also result in faster builds since less code generation has to be performed. */ + removeAvailableModules?: boolean; + /** Empty chunks are removed. This reduces load in filesystem and results in faster builds. */ + removeEmptyChunks?: boolean; + /** Equal chunks are merged. This results in less code generation and faster builds. */ + mergeDuplicateChunks?: boolean; + /** Chunks which are subsets of other chunks are determined and flagged in a way that subsets don’t have to be loaded when the bigger chunk has been loaded. */ + flagIncludedChunks?: boolean; + /** Give more often used ids smaller (shorter) values. */ + occurrenceOrder?: boolean; + /** Determine exports for each module when possible. This information is used by other optimizations or code generation. I. e. to generate more efficient code for export * from. */ + providedExports?: boolean; + /** Determine used exports for each module. This depends on optimization.providedExports. This information is used by other optimizations or code generation. + * I. e. exports are not generated for unused exports, export names are mangled to single char identifiers when all usages are compatible. DCE in minimizers will benefit from this and can remove unused exports. */ + usedExports?: boolean; + /** Recognise the sideEffects flag in package.json or rules to eliminate modules. This depends on optimization.providedExports and optimization.usedExports. + * These dependencies have a cost, but eliminating modules has positive impact on performance because of less code generation. It depends on your codebase. + * Try it for possible performance wins. */ + sideEffects?: boolean; + /** Tries to find segments of the module graph which can be safely concatenated into a single module. Depends on optimization.providedExports and optimization.usedExports. */ + concatenateModules?: boolean; + /** Finds modules which are shared between chunk and splits them into separate chunks to reduce duplication or separate vendor modules from application modules. */ + splitChunks?: boolean; + /** Create a separate chunk for the webpack runtime code and chunk manifest. This chunk should be inlined into the HTML */ + runtimeChunk?: boolean; + /** Don’t write output assets when compilation errors. */ + noEmitOnErrors?: boolean; + /** Instead of numeric ids, give modules useful names. */ + namedModules?: boolean; + /** Instead of numeric ids, give chunks useful names. */ + namedChunks?: boolean; + /** Defines the process.env.NODE_ENV constant to a compile-time-constant value. This allows to remove development only code from code. */ + nodeEnv?: boolean; + /** Use the minimizer (optimization.minimizer, by default uglify-js) to minimize output assets. */ + minimize?: boolean; + /** Identifiers used in records are relative to context directory. */ + portableRecords?: boolean; + } } // tslint:disable-next-line:interface-name From ee6770df50f6e893d2a47e3e41510378963893cc Mon Sep 17 00:00:00 2001 From: Dennis George Date: Tue, 27 Feb 2018 13:51:14 -0600 Subject: [PATCH 2/9] updated webpack 4.0 optimization options comments for linter --- types/webpack/index.d.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/types/webpack/index.d.ts b/types/webpack/index.d.ts index 06483792cd..fbc0d9f636 100644 --- a/types/webpack/index.d.ts +++ b/types/webpack/index.d.ts @@ -503,8 +503,10 @@ declare namespace webpack { type WatchOptions = ICompiler.WatchOptions; interface Optimization { - /** Modules are removed from chunks when they are already available in all parent chunk groups. - * This reduces asset size. Smaller assets also result in faster builds since less code generation has to be performed. */ + /** + * Modules are removed from chunks when they are already available in all parent chunk groups. + * This reduces asset size. Smaller assets also result in faster builds since less code generation has to be performed. + */ removeAvailableModules?: boolean; /** Empty chunks are removed. This reduces load in filesystem and results in faster builds. */ removeEmptyChunks?: boolean; @@ -516,12 +518,17 @@ declare namespace webpack { occurrenceOrder?: boolean; /** Determine exports for each module when possible. This information is used by other optimizations or code generation. I. e. to generate more efficient code for export * from. */ providedExports?: boolean; - /** Determine used exports for each module. This depends on optimization.providedExports. This information is used by other optimizations or code generation. - * I. e. exports are not generated for unused exports, export names are mangled to single char identifiers when all usages are compatible. DCE in minimizers will benefit from this and can remove unused exports. */ + /** + * Determine used exports for each module. This depends on optimization.providedExports. This information is used by other optimizations or code generation. + * I. e. exports are not generated for unused exports, export names are mangled to single char identifiers when all usages are compatible. + * DCE in minimizers will benefit from this and can remove unused exports. + */ usedExports?: boolean; - /** Recognise the sideEffects flag in package.json or rules to eliminate modules. This depends on optimization.providedExports and optimization.usedExports. + /** + * Recognise the sideEffects flag in package.json or rules to eliminate modules. This depends on optimization.providedExports and optimization.usedExports. * These dependencies have a cost, but eliminating modules has positive impact on performance because of less code generation. It depends on your codebase. - * Try it for possible performance wins. */ + * Try it for possible performance wins. + */ sideEffects?: boolean; /** Tries to find segments of the module graph which can be safely concatenated into a single module. Depends on optimization.providedExports and optimization.usedExports. */ concatenateModules?: boolean; From be525690a83492681ee6e28d45839ccffbfb82b4 Mon Sep 17 00:00:00 2001 From: Dennis George Date: Tue, 27 Feb 2018 14:18:59 -0600 Subject: [PATCH 3/9] updated for webpack 4.0 added optimization.minimizer option --- types/webpack/index.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/types/webpack/index.d.ts b/types/webpack/index.d.ts index fbc0d9f636..f704797f58 100644 --- a/types/webpack/index.d.ts +++ b/types/webpack/index.d.ts @@ -546,6 +546,8 @@ declare namespace webpack { nodeEnv?: boolean; /** Use the minimizer (optimization.minimizer, by default uglify-js) to minimize output assets. */ minimize?: boolean; + /** Configure minimzers and options TODO: add type for this */ + minimizer?: any; /** Identifiers used in records are relative to context directory. */ portableRecords?: boolean; } From 76cfb34e13ca0edc556d3fc48096fbf4b79fe186 Mon Sep 17 00:00:00 2001 From: Dennis George Date: Tue, 27 Feb 2018 15:48:32 -0600 Subject: [PATCH 4/9] updated webpack to be 4.0 specific; added v3 subfolder for old version --- types/webpack/index.d.ts | 98 +-- types/webpack/v3/index.d.ts | 1301 +++++++++++++++++++++++++++++ types/webpack/v3/package.json | 6 + types/webpack/v3/tsconfig.json | 26 + types/webpack/v3/tslint.json | 3 + types/webpack/v3/webpack-tests.ts | 667 +++++++++++++++ 6 files changed, 2025 insertions(+), 76 deletions(-) create mode 100644 types/webpack/v3/index.d.ts create mode 100644 types/webpack/v3/package.json create mode 100644 types/webpack/v3/tsconfig.json create mode 100644 types/webpack/v3/tslint.json create mode 100644 types/webpack/v3/webpack-tests.ts diff --git a/types/webpack/index.d.ts b/types/webpack/index.d.ts index f704797f58..9b84ff7731 100644 --- a/types/webpack/index.d.ts +++ b/types/webpack/index.d.ts @@ -187,9 +187,13 @@ declare namespace webpack { sourcePrefix?: string; /** This option enables cross-origin loading of chunks. */ crossOriginLoading?: string | boolean; + /** A Constructor to a custom hash function. You can provide a non-crypto hash function for performance reasons */ + hashFunction?: (algorithm: string, options?: any) => any; + /** Allow to choose the global object reference in runtime exitCode. */ + globalObject?: any; } - interface BaseModule { + interface Module { /** A array of applied pre loaders. */ preLoaders?: Rule[]; /** A array of applied post loaders. */ @@ -208,18 +212,10 @@ declare namespace webpack { wrappedContextRecursive?: boolean; wrappedContextCritical?: boolean; strictExportPresence?: boolean; - } - interface OldModule extends BaseModule { - /** An array of automatically applied loaders. */ - loaders: Rule[]; - } - interface NewModule extends BaseModule { /** An array of rules applied for modules. */ rules: Rule[]; } - type Module = OldModule | NewModule; - interface Resolve { /** * A list of directories to resolve modules from. @@ -381,7 +377,10 @@ declare namespace webpack { options?: { [name: string]: any }; } type Loader = string | OldLoader | NewLoader; - + interface ParserOptions { + [optName: string]: any; + system?: boolean; + } /** * There are direct and delegate rules. Direct Rules need a test, Delegate rules delegate to subrules bringing their own. * Direct rules can optionally contain delegate keys (oneOf, rules). @@ -421,11 +420,17 @@ declare namespace webpack { * For each different parser options object a new parser is created and plugins can apply plugins depending on the parser options. * Many of the default plugins apply their parser plugins only if a property in the parser options is not set or true. */ - parser?: { [optName: string]: any }; + parser?: ParserOptions; /** An array of Rules that is also used when the Rule matches. */ rules?: Rule[]; /** An array of Rules from which only the first matching Rule is used when the Rule matches. */ oneOf?: Rule[]; + /** Configures module resolving. */ + resolve?: Resolve; + /** Configures the module type. */ + type?: "javascript/auto" | "javascript/esm" | "javascript/dynamic" | "json" | "webassembly/experimental"; + /** TODO: Update this when the v4 documentation is complete. */ + sideEffects?: any; } interface BaseDirectRule extends BaseRule { /** A condition that must be met */ @@ -884,6 +889,7 @@ declare namespace webpack { constructor(options: any); } + /** @deprecated use config.optimization.namedModules */ class NamedModulesPlugin extends Plugin { constructor(); } @@ -892,15 +898,12 @@ declare namespace webpack { constructor(nameResolver?: (chunk: any) => string | null); } + /** @deprecated use config.optimization.noEmitOnErrors */ class NoEmitOnErrorsPlugin extends Plugin { constructor(); } /** @deprecated use webpack.NoEmitOnErrorsPlugin */ - class NoErrorsPlugin extends Plugin { - constructor(); - } - class NormalModuleReplacementPlugin extends Plugin { constructor(resourceRegExp: any, newResource: any); } @@ -954,6 +957,7 @@ declare namespace webpack { } namespace optimize { + /** @deprecated use config.optimization.concatenateModules */ class ModuleConcatenationPlugin extends Plugin { } class AggressiveMergingPlugin extends Plugin { constructor(options?: AggressiveMergingPlugin.Options); @@ -980,62 +984,6 @@ declare namespace webpack { } } - class CommonsChunkPlugin extends Plugin { - constructor(options?: CommonsChunkPlugin.Options); - } - - namespace CommonsChunkPlugin { - type MinChunksFn = (module: any, count: number) => boolean; - - interface Options { - /** - * The chunk name of the commons chunk. An existing chunk can be selected by passing a name of an existing chunk. - * If an array of strings is passed this is equal to invoking the plugin multiple times for each chunk name. - * If omitted and `options.async` or `options.children` is set all chunks are used, - * otherwise `options.filename` is used as chunk name. - */ - name?: string; - names?: string[]; - - /** - * The filename template for the commons chunk. Can contain the same placeholders as `output.filename`. - * If omitted the original filename is not modified (usually `output.filename` or `output.chunkFilename`). - */ - filename?: string; - - /** - * The minimum number of chunks which need to contain a module before it's moved into the commons chunk. - * The number must be greater than or equal 2 and lower than or equal to the number of chunks. - * Passing `Infinity` just creates the commons chunk, but moves no modules into it. - * By providing a `function` you can add custom logic. (Defaults to the number of chunks) - */ - minChunks?: number | MinChunksFn; - - /** - * Select the source chunks by chunk names. The chunk must be a child of the commons chunk. - * If omitted all entry chunks are selected. - */ - chunks?: string[]; - - /** - * If `true` all children of the commons chunk are selected - */ - children?: boolean; - - /** - * If `true` a new async commons chunk is created as child of `options.name` and sibling of `options.chunks`. - * It is loaded in parallel with `options.chunks`. It is possible to change the name of the output file - * by providing the desired string instead of `true`. - */ - async?: boolean | string; - - /** - * Minimum size of all common module before a commons chunk is created. - */ - minSize?: number; - } - } - /** @deprecated */ class DedupePlugin extends Plugin { constructor(); @@ -1252,11 +1200,6 @@ declare namespace webpack { */ inputValue: any; - /** - * The options passed to the Compiler. - */ - options: any; - /** * A boolean flag. It is set when in debug mode. */ @@ -1311,6 +1254,9 @@ declare namespace webpack { * Hacky access to the Module object being loaded. */ _module: any; + + /** Flag if HMR is enabled */ + hot: boolean; } } diff --git a/types/webpack/v3/index.d.ts b/types/webpack/v3/index.d.ts new file mode 100644 index 0000000000..ee3a291d02 --- /dev/null +++ b/types/webpack/v3/index.d.ts @@ -0,0 +1,1301 @@ +// Type definitions for webpack 3.8 +// Project: https://github.com/webpack/webpack +// Definitions by: Qubo +// Benjamin Lim +// Boris Cherny +// Tommy Troy Lin +// Mohsen Azimi +// Jonathan Creamer +// Ahmed T. Ali +// Alan Agius +// Spencer Elliott +// Jason Cheatham +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +/// + +import Tapable = require('tapable'); +import * as UglifyJS from 'uglify-js'; +import { RawSourceMap } from 'source-map'; + +export = webpack; + +declare function webpack( + options: webpack.Configuration, + handler: webpack.Compiler.Handler +): webpack.Compiler.Watching | webpack.Compiler; +declare function webpack(options?: webpack.Configuration): webpack.Compiler; + +declare function webpack( + options: webpack.Configuration[], + handler: webpack.MultiCompiler.Handler +): webpack.MultiWatching | webpack.MultiCompiler; +declare function webpack(options: webpack.Configuration[]): webpack.MultiCompiler; + +declare namespace webpack { + interface Configuration { + /** Name of the configuration. Used when loading multiple configurations. */ + name?: string; + /** + * The base directory (absolute path!) for resolving the `entry` option. + * If `output.pathinfo` is set, the included pathinfo is shortened to this directory. + */ + context?: string; + entry?: string | string[] | Entry | EntryFunc; + /** Choose a style of source mapping to enhance the debugging process. These values can affect build and rebuild speed dramatically. */ + devtool?: Options.Devtool; + /** 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.
  • + *
  • "electron-renderer" Compile for Electron for renderer process, providing a target using JsonpTemplatePlugin, FunctionModulePlugin + * for browser environments and NodeTargetPlugin and ExternalsPlugin for CommonJS and Electron built-in modules.
  • + *
  • "electron-main" Compile for Electron for main process.
  • + *
  • "atom" Alias for electron-main
  • + *
  • "electron" Alias for electron-main
  • + *
      + */ + target?: 'web' | 'webworker' | 'node' | 'async-node' | 'node-webkit' | 'atom' | 'electron' | 'electron-renderer' | 'electron-main' | ((compiler?: any) => void); + /** 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 | object; + /** Enter watch mode, which rebuilds on file change. */ + watch?: boolean; + watchOptions?: Options.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[]; + /** Stats options for logging */ + stats?: Options.Stats; + /** Performance options */ + performance?: Options.Performance; + /** Limit the number of parallel processed modules. Can be used to fine tune performance or to get more reliable profiling results */ + parallelism?: number; + } + + interface Entry { + [name: string]: string | string[]; + } + + type EntryFunc = () => (string | string[] | Promise); + + interface DevtoolModuleFilenameTemplateInfo { + identifier: string; + shortIdentifier: string; + resource: any; + resourcePath: string; + absoluteResourcePath: string; + allLoaders: any[]; + query: string; + moduleId: string; + hash: string; + } + + 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 | ((info: DevtoolModuleFilenameTemplateInfo) => string); + /** Similar to output.devtoolModuleFilenameTemplate, but used in the case of duplicate module identifiers. */ + devtoolFallbackModuleFilenameTemplate?: string | ((info: DevtoolModuleFilenameTemplateInfo) => 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?: string | string[]; + /** + * 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
      • + *
      • "window" - Assign to widnow
      • + *
      • "assign" - Assign to a global variable
      • + *
      • "jsonp" - Generate Webpack JSONP module
      • + *
      + */ + libraryTarget?: 'var' | 'this' | 'commonjs' | 'commonjs2' | 'amd' | 'umd' | 'window' | 'assign' | 'jsonp'; + /** Configure which module or modules will be exposed via the `libraryTarget` */ + libraryExport?: string | 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 BaseModule { + /** A array of applied pre loaders. */ + preLoaders?: Rule[]; + /** A array of applied post loaders. */ + postLoaders?: Rule[]; + /** A RegExp or an array of RegExps. Don’t parse files matching. */ + noParse?: RegExp | RegExp[] | ((content: string) => boolean); + unknownContextRequest?: string; + unknownContextRecursive?: boolean; + unknownContextRegExp?: RegExp; + unknownContextCritical?: boolean; + exprContextRequest?: string; + exprContextRegExp?: RegExp; + exprContextRecursive?: boolean; + exprContextCritical?: boolean; + wrappedContextRegExp?: RegExp; + wrappedContextRecursive?: boolean; + wrappedContextCritical?: boolean; + strictExportPresence?: boolean; + } + interface OldModule extends BaseModule { + /** An array of automatically applied loaders. */ + loaders: Rule[]; + } + interface NewModule extends BaseModule { + /** An array of rules applied for modules. */ + rules: Rule[]; + } + + type Module = OldModule | NewModule; + + interface Resolve { + /** + * A list of directories to resolve modules from. + * + * Absolute paths will be searched once. + * + * If an entry is relative, will be resolved using node's resolution algorithm + * relative to the requested file. + * + * Defaults to `["node_modules"]` + */ + modules?: string[]; + + /** + * A list of package description files to search for. + * + * Defaults to `["package.json"]` + */ + descriptionFiles?: string[]; + + /** + * A list of fields in a package description object to use for finding + * the entry point. + * + * Defaults to `["browser", "module", "main"]` or `["module", "main"]`, + * depending on the value of the `target` `Configuration` value. + */ + mainFields?: string[]; + + /** + * A list of fields in a package description object to try to parse + * in the same format as the `alias` resolve option. + * + * Defaults to `["browser"]` or `[]`, depending on the value of the + * `target` `Configuration` value. + * + * @see alias + */ + aliasFields?: string[]; + + /** + * A list of file names to search for when requiring directories that + * don't contain a package description file. + * + * Defaults to `["index"]`. + */ + mainFiles?: string[]; + + /** + * A list of file extensions to try when requesting files. + * + * An empty string is considered invalid. + */ + extensions?: string[]; + + /** + * If true, requires that all requested paths must use an extension + * from `extensions`. + */ + enforceExtension?: boolean; + + /** + * Replace the given module requests with other modules or paths. + * + * @see aliasFields + */ + alias?: { [key: string]: string; }; + + /** + * Whether to use a cache for resolving, or the specific object + * to use for caching. Sharing objects may be useful when running + * multiple webpack compilers. + * + * Defaults to `true`. + */ + unsafeCache?: {} | boolean; + + /** + * A function used to decide whether to cache the given resolve request. + * + * Defaults to `() => true`. + */ + cachePredicate?(data: { path: string, request: string }): boolean; + + /** + * A list of additional resolve plugins which should be applied. + */ + plugins?: ResolvePlugin[]; + + /** + * Whether to resolve symlinks to their symlinked location. + * + * Defaults to `true` + */ + symlinks?: boolean; + } + + interface ResolveLoader extends Resolve { + /** + * List of strings to append to a loader's name when trying to resolve it. + */ + moduleExtensions?: string[]; + + enforceModuleExtension?: boolean; + } + + type ExternalsElement = string | RegExp | ExternalsObjectElement | ExternalsFunctionElement; + + interface ExternalsObjectElement { + [key: string]: boolean | string; + } + + type ExternalsFunctionElement = (context: any, request: any, callback: (error: any, result: any) => void) => any; + + interface Node { + console?: boolean; + global?: boolean; + process?: boolean; + Buffer?: boolean; + __filename?: boolean | string; + __dirname?: boolean | string; + [nodeBuiltin: string]: boolean | string | undefined; + } + + interface BaseConditionSpec { + /** The Condition must match. The convention is the provide a string or array of strings here, but it's not enforced. */ + include?: Condition; + /** The Condition must NOT match. The convention is the provide a string or array of strings here, but it's not enforced. */ + exclude?: Condition; + } + interface TestConditionSpec extends BaseConditionSpec { + /** The Condition must match. The convention is the provide a RegExp or array of RegExps here, but it's not enforced. */ + test: Condition; + } + interface AndConditionSpec extends BaseConditionSpec { + /** All Conditions must match. */ + and: Condition[]; + } + interface OrConditionSpec extends BaseConditionSpec { + /** Any Condition must match. */ + or: Condition[]; + } + interface NotConditionSpec extends BaseConditionSpec { + /** The Condition must NOT match. */ + not: Condition; + } + type ConditionSpec = TestConditionSpec | OrConditionSpec | AndConditionSpec | NotConditionSpec; + + // tslint:disable-next-line:no-empty-interface + interface ConditionArray extends Array { } + type Condition = string | RegExp | ((absPath: string) => boolean) | ConditionSpec | ConditionArray; + + interface OldLoader { + loader: string; + query?: { [name: string]: any }; + } + interface NewLoader { + loader: string; + options?: { [name: string]: any }; + } + type Loader = string | OldLoader | NewLoader; + + /** + * There are direct and delegate rules. Direct Rules need a test, Delegate rules delegate to subrules bringing their own. + * Direct rules can optionally contain delegate keys (oneOf, rules). + * + * These types exist to enforce that a rule has the keys `((loader XOR loaders) AND test) OR oneOf OR rules` + */ + interface BaseRule { + /** + * Specifies the category of the loader. No value means normal loader. + * + * There is also an additional category "inlined loader" which are loaders applied inline of the import/require. + * + * All loaders are sorted in the order post, inline, normal, pre and used in this order. + * + * All normal loaders can be omitted (overridden) by prefixing ! in the request. + * + * All normal and pre loaders can be omitted (overridden) by prefixing -! in the request. + * + * All normal, post and pre loaders can be omitted (overridden) by prefixing !! in the request. + * + * Inline loaders and ! prefixes should not be used as they are non-standard. They may be use by loader generated code. + */ + enforce?: 'pre' | 'post'; + /** A condition that must be met */ + test?: Condition | Condition[]; + /** A condition that must not be met */ + exclude?: Condition | Condition[]; + /** A condition that must be met */ + include?: Condition | Condition[]; + /** A Condition matched with the resource. */ + resource?: Condition | Condition[]; + /** A condition matched with the issuer */ + issuer?: Condition | Condition[]; + /** + * An object with parser options. All applied parser options are merged. + * + * For each different parser options object a new parser is created and plugins can apply plugins depending on the parser options. + * Many of the default plugins apply their parser plugins only if a property in the parser options is not set or true. + */ + parser?: { [optName: string]: any }; + /** An array of Rules that is also used when the Rule matches. */ + rules?: Rule[]; + /** An array of Rules from which only the first matching Rule is used when the Rule matches. */ + oneOf?: Rule[]; + } + interface BaseDirectRule extends BaseRule { + /** A condition that must be met */ + test: Condition | Condition[]; + } + // Direct Rules + interface BaseSingleLoaderRule extends BaseDirectRule { + /** Loader name or an object with name and options */ + loader: Loader; + } + interface OldLoaderRule extends BaseSingleLoaderRule { + /** + * Loader options + * @deprecated: + */ + query?: { [name: string]: any }; + } + interface NewLoaderRule extends BaseSingleLoaderRule { + options?: { [name: string]: any }; + } + type LoaderRule = OldLoaderRule | NewLoaderRule; + interface OldUseRule extends BaseDirectRule { + /** + * A array of loaders. + * @deprecated use `use` instead + */ + loaders: string[]; + } + interface NewUseRule extends BaseDirectRule { + /** A loader or array of loaders */ + use: Loader | Loader[]; + } + type UseRule = OldUseRule | NewUseRule; + + // Delegate Rules + interface RulesRule extends BaseRule { + /** An array of Rules that is also used when the Rule matches. */ + rules: Rule[]; + } + interface OneOfRule extends BaseRule { + oneOf: Rule[]; + } + type Rule = LoaderRule | UseRule | RulesRule | OneOfRule; + + namespace Options { + // tslint:disable-next-line:max-line-length + type Devtool = 'eval' | 'inline-source-map' | 'cheap-eval-source-map' | 'cheap-source-map' | 'cheap-module-eval-source-map' | 'cheap-module-source-map' | 'eval-source-map' | 'source-map' | + 'nosources-source-map' | 'hidden-source-map' | 'nosources-source-map' | '@eval' | '@inline-source-map' | '@cheap-eval-source-map' | '@cheap-source-map' | '@cheap-module-eval-source-map' | + '@cheap-module-source-map' | '@eval-source-map' | '@source-map' | '@nosources-source-map' | '@hidden-source-map' | '@nosources-source-map' | '#eval' | '#inline-source-map' | + '#cheap-eval-source-map' | '#cheap-source-map' | '#cheap-module-eval-source-map' | '#cheap-module-source-map' | '#eval-source-map' | '#source-map' | '#nosources-source-map' | + '#hidden-source-map' | '#nosources-source-map' | '#@eval' | '#@inline-source-map' | '#@cheap-eval-source-map' | '#@cheap-source-map' | '#@cheap-module-eval-source-map' | + '#@cheap-module-source-map' | '#@eval-source-map' | '#@source-map' | '#@nosources-source-map' | '#@hidden-source-map' | '#@nosources-source-map' | boolean; + + interface Performance { + /** This property allows webpack to control what files are used to calculate performance hints. */ + assetFilter?(assetFilename: string): boolean; + /** + * Turns hints on/off. In addition, tells webpack to throw either an error or a warning when hints are + * found. This property is set to "warning" by default. + */ + hints?: 'warning' | 'error' | false; + /** + * An asset is any emitted file from webpack. This option controls when webpack emits a performance hint + * based on individual asset size. The default value is 250000 (bytes). + */ + maxAssetSize?: number; + /** + * An entrypoint represents all assets that would be utilized during initial load time for a specific entry. + * This option controls when webpack should emit performance hints based on the maximum entrypoint size. + * The default value is 250000 (bytes). + */ + maxEntrypointSize?: number; + } + type Stats = Stats.ToStringOptions; + type WatchOptions = ICompiler.WatchOptions; + } + + // tslint:disable-next-line:interface-name + interface ICompiler { + run(handler: ICompiler.Handler): void; + watch(watchOptions: ICompiler.WatchOptions, handler: ICompiler.Handler): Watching; + } + + namespace ICompiler { + type Handler = (err: Error, stats: Stats) => void; + + interface WatchOptions { + /** + * Add a delay before rebuilding once the first file changed. This allows webpack to aggregate any other + * changes made during this time period into one rebuild. + * Pass a value in milliseconds. Default: 300. + */ + aggregateTimeout?: number; + /** + * For some systems, watching many file systems can result in a lot of CPU or memory usage. + * It is possible to exclude a huge folder like node_modules. + * It is also possible to use anymatch patterns. + */ + ignored?: string | string[] | RegExp; + /** Turn on polling by passing true, or specifying a poll interval in milliseconds. */ + poll?: boolean | number; + } + } + + interface Watching { + close(callback: () => void): void; + invalidate(): void; + } + + class Compiler extends Tapable implements ICompiler { + constructor(); + + name: string; + options: Configuration; + outputFileSystem: any; + run(handler: Compiler.Handler): void; + watch(watchOptions: Compiler.WatchOptions, handler: Compiler.Handler): Compiler.Watching; + } + + namespace Compiler { + type Handler = ICompiler.Handler; + type WatchOptions = ICompiler.WatchOptions; + + class Watching implements Watching { + constructor(compiler: Compiler, watchOptions: Watching.WatchOptions, handler: Watching.Handler); + + close(callback: () => void): void; + invalidate(): void; + } + + namespace Watching { + type WatchOptions = ICompiler.WatchOptions; + type Handler = ICompiler.Handler; + } + } + + abstract class MultiCompiler extends Tapable implements ICompiler { + compilers: ICompiler[]; + run(handler: MultiCompiler.Handler): void; + watch(watchOptions: MultiCompiler.WatchOptions, handler: MultiCompiler.Handler): MultiWatching; + } + + namespace MultiCompiler { + type Handler = ICompiler.Handler; + type WatchOptions = ICompiler.WatchOptions; + } + + abstract class MultiWatching implements Watching { + close(callback: () => void): void; + invalidate(): void; + } + + abstract class Plugin implements Tapable.Plugin { + apply(compiler: Compiler): void; + } + + abstract class ResolvePlugin implements Tapable.Plugin { + apply(resolver: any /* EnhancedResolve.Resolver */): void; + } + + abstract class Stats { + /** Returns true if there were errors while compiling. */ + hasErrors(): boolean; + /** Returns true if there were warnings while compiling. */ + hasWarnings(): boolean; + /** Returns compilation information as a JSON object. */ + toJson(options?: Stats.ToJsonOptions): any; + /** Returns a formatted string of the compilation information (similar to CLI output). */ + toString(options?: Stats.ToStringOptions): string; + } + + namespace Stats { + type Preset + = boolean + | 'errors-only' + | 'minimal' + | 'none' + | 'normal' + | 'verbose'; + + interface ToJsonOptionsObject { + /** Add asset Information */ + assets?: boolean; + /** Sort assets by a field */ + assetsSort?: string; + /** Add information about cached (not built) modules */ + cached?: boolean; + /** Show cached assets (setting this to `false` only shows emitted files) */ + cachedAssets?: boolean; + /** Add children information */ + children?: boolean; + /** Add built modules information to chunk information */ + chunkModules?: boolean; + /** Add the origins of chunks and chunk merging info */ + chunkOrigins?: boolean; + /** Add chunk information (setting this to `false` allows for a less verbose output) */ + chunks?: boolean; + /** Sort the chunks by a field */ + chunksSort?: string; + /** Context directory for request shortening */ + context?: string; + /** Display the distance from the entry point for each module */ + depth?: boolean; + /** Display the entry points with the corresponding bundles */ + entrypoints?: boolean; + /** Add --env information */ + env?: boolean; + /** Add errors */ + errors?: boolean; + /** Add details to errors (like resolving log) */ + errorDetails?: boolean; + /** Exclude assets from being displayed in stats */ + excludeAssets?: StatsExcludeFilter; + /** Exclude modules from being displayed in stats */ + excludeModules?: StatsExcludeFilter; + /** See excludeModules */ + exclude?: StatsExcludeFilter; + /** Add the hash of the compilation */ + hash?: boolean; + /** Set the maximum number of modules to be shown */ + maxModules?: number; + /** Add built modules information */ + modules?: boolean; + /** Sort the modules by a field */ + modulesSort?: string; + /** Show dependencies and origin of warnings/errors */ + moduleTrace?: boolean; + /** Add public path information */ + publicPath?: boolean; + /** Add information about the reasons why modules are included */ + reasons?: boolean; + /** Add the source code of modules */ + source?: boolean; + /** Add timing information */ + timings?: boolean; + /** Add webpack version information */ + version?: boolean; + /** Add warnings */ + warnings?: boolean; + /** Show which exports of a module are used */ + usedExports?: boolean; + /** Filter warnings to be shown */ + warningsFilter?: string | RegExp | Array | ((warning: string) => boolean); + /** Show performance hint when file size exceeds `performance.maxAssetSize` */ + performance?: boolean; + /** Show the exports of the modules */ + providedExports?: boolean; + } + + type ToJsonOptions = Preset | ToJsonOptionsObject; + + type StatsExcludeFilter = string | string[] | RegExp | RegExp[] | ((assetName: string) => boolean) | Array<(assetName: string) => boolean>; + + interface ToStringOptionsObject extends ToJsonOptionsObject { + /** `webpack --colors` equivalent */ + colors?: boolean; + } + + type ToStringOptions = Preset | ToStringOptionsObject; + } + + /** + * Plugins + */ + + class BannerPlugin extends Plugin { + constructor(options: string | BannerPlugin.Options); + } + + namespace BannerPlugin { + type Filter = string | RegExp; + + interface Options { + banner: string; + entryOnly?: boolean; + exclude?: Filter | Filter[]; + include?: Filter | Filter[]; + raw?: boolean; + test?: Filter | Filter[]; + } + } + + class ContextReplacementPlugin extends Plugin { + constructor(resourceRegExp: any, newContentResource?: any, newContentRecursive?: any, newContentRegExp?: any); + } + + class DefinePlugin extends Plugin { + constructor(definitions: { [key: string]: any }); + } + + class DllPlugin extends Plugin { + constructor(options: DllPlugin.Options | DllPlugin.Options[]); + } + + namespace DllPlugin { + interface Options { + /** + * The context of requests in the manifest file. + * + * Defaults to the webpack context. + */ + context?: string; + + /** + * The name of the exposed DLL function (keep consistent with `output.library`). + */ + name: string; + + /** + * The absolute path to the manifest json file (output). + */ + path: string; + } + } + + class DllReferencePlugin extends Plugin { + constructor(options: DllReferencePlugin.Options); + } + + namespace DllReferencePlugin { + interface Options { + /** + * The mappings from the request to module ID. + * + * Defaults to `manifest.content`. + */ + content?: any; + + /** + * The context of requests in the manifest (or content property). + * + * This is an absolute path. + */ + context: string; + + /** + * An object containing `content` and `name`. + */ + manifest: { content: string, name: string } | string; + + /** + * The name where the DLL is exposed. + * + * Defaults to `manifest.name`. + * + * See also `externals`. + */ + name?: string; + + /** + * The prefix which is used for accessing the content of the DLL. + */ + scope?: string; + + /** + * The type how the DLL is exposed. + * + * Defaults to `"var"`. + * + * See also `externals`. + */ + sourceType?: string; + } + } + + class EvalSourceMapDevToolPlugin extends Plugin { + constructor(options?: false | string | EvalSourceMapDevToolPlugin.Options); + } + + namespace EvalSourceMapDevToolPlugin { + interface Options { + append?: false | string; + columns?: boolean; + lineToLine?: boolean | { + exclude?: Condition | Condition[]; + include?: Condition | Condition[]; + test?: Condition | Condition[]; + }; + module?: boolean; + moduleFilenameTemplate?: string; + sourceRoot?: string; + } + } + + class ExtendedAPIPlugin extends Plugin { + constructor(); + } + + class HashedModuleIdsPlugin extends Plugin { + constructor(options?: { + hashFunction?: string, + hashDigest?: string, + hashDigestLength?: number + }); + } + + class HotModuleReplacementPlugin extends Plugin { + constructor(options?: any); + } + + class IgnorePlugin extends Plugin { + constructor(requestRegExp: any, contextRegExp?: any); + } + + class LoaderOptionsPlugin extends Plugin { + constructor(options: any); + } + + class NamedModulesPlugin extends Plugin { + constructor(); + } + + class NamedChunksPlugin extends Plugin { + constructor(nameResolver?: (chunk: any) => string | null); + } + + class NoEmitOnErrorsPlugin extends Plugin { + constructor(); + } + + /** @deprecated use webpack.NoEmitOnErrorsPlugin */ + class NoErrorsPlugin extends Plugin { + constructor(); + } + + class NormalModuleReplacementPlugin extends Plugin { + constructor(resourceRegExp: any, newResource: any); + } + + class PrefetchPlugin extends Plugin { + // tslint:disable-next-line:unified-signatures + constructor(context: any, request: any); + constructor(request: any); + } + + class ProgressPlugin extends Plugin { + constructor(options?: (percentage: number, msg: string, moduleProgress?: string, activeModules?: string, moduleName?: string) => void); + } + + class EnvironmentPlugin extends Plugin { + constructor(envs: string[] | { [key: string]: any }); + } + + class ProvidePlugin extends Plugin { + constructor(definitions: { [key: string]: any }); + } + + class SourceMapDevToolPlugin extends Plugin { + constructor(options?: null | false | string | SourceMapDevToolPlugin.Options); + } + + namespace SourceMapDevToolPlugin { + /** @todo extend EvalSourceMapDevToolPlugin.Options */ + interface Options { + append?: false | string; + columns?: boolean; + exclude?: Condition | Condition[]; + fallbackModuleFilenameTemplate?: string; + filename?: null | false | string; + include?: Condition | Condition[]; + lineToLine?: boolean | { + exclude?: Condition | Condition[]; + include?: Condition | Condition[]; + test?: Condition | Condition[]; + }; + module?: boolean; + moduleFilenameTemplate?: string; + noSources?: boolean; + sourceRoot?: null | string; + test?: Condition | Condition[]; + } + } + + class WatchIgnorePlugin extends Plugin { + constructor(paths: Array); + } + + namespace optimize { + class ModuleConcatenationPlugin extends Plugin { } + class AggressiveMergingPlugin extends Plugin { + constructor(options?: AggressiveMergingPlugin.Options); + } + + namespace AggressiveMergingPlugin { + interface Options { + /** + * When options.moveToParents is set, moving to an entry chunk is more expensive. + * Defaults to 10, which means moving to an entry chunk is ten times more expensive than moving to a + * normal chunk. + */ + entryChunkMultiplicator?: number; + /** + * A factor which defines the minimum required size reduction for chunk merging. + * Defaults to 1.5 which means that the total size needs to be reduced by 50% for chunk merging. + */ + minSizeReduce?: number; + /** + * When set, modules that are not in both merged chunks are moved to all parents of the chunk. + * Defaults to false. + */ + moveToParents?: boolean; + } + } + + class CommonsChunkPlugin extends Plugin { + constructor(options?: CommonsChunkPlugin.Options); + } + + namespace CommonsChunkPlugin { + type MinChunksFn = (module: any, count: number) => boolean; + + interface Options { + /** + * The chunk name of the commons chunk. An existing chunk can be selected by passing a name of an existing chunk. + * If an array of strings is passed this is equal to invoking the plugin multiple times for each chunk name. + * If omitted and `options.async` or `options.children` is set all chunks are used, + * otherwise `options.filename` is used as chunk name. + */ + name?: string; + names?: string[]; + + /** + * The filename template for the commons chunk. Can contain the same placeholders as `output.filename`. + * If omitted the original filename is not modified (usually `output.filename` or `output.chunkFilename`). + */ + filename?: string; + + /** + * The minimum number of chunks which need to contain a module before it's moved into the commons chunk. + * The number must be greater than or equal 2 and lower than or equal to the number of chunks. + * Passing `Infinity` just creates the commons chunk, but moves no modules into it. + * By providing a `function` you can add custom logic. (Defaults to the number of chunks) + */ + minChunks?: number | MinChunksFn; + + /** + * Select the source chunks by chunk names. The chunk must be a child of the commons chunk. + * If omitted all entry chunks are selected. + */ + chunks?: string[]; + + /** + * If `true` all children of the commons chunk are selected + */ + children?: boolean; + + /** + * If `true` a new async commons chunk is created as child of `options.name` and sibling of `options.chunks`. + * It is loaded in parallel with `options.chunks`. It is possible to change the name of the output file + * by providing the desired string instead of `true`. + */ + async?: boolean | string; + + /** + * Minimum size of all common module before a commons chunk is created. + */ + minSize?: number; + } + } + + /** @deprecated */ + class DedupePlugin extends Plugin { + constructor(); + } + + class LimitChunkCountPlugin extends Plugin { + constructor(options: any); + } + + class MinChunkSizePlugin extends Plugin { + constructor(options: any); + } + + class OccurrenceOrderPlugin extends Plugin { + constructor(preferEntry: boolean); + } + + class UglifyJsPlugin extends Plugin { + constructor(options?: UglifyJsPlugin.Options); + } + + namespace UglifyJsPlugin { + type CommentFilter = (astNode: any, comment: any) => boolean; + + interface Options extends UglifyJS.MinifyOptions { + beautify?: boolean; + comments?: boolean | RegExp | CommentFilter; + exclude?: Condition | Condition[]; + include?: Condition | Condition[]; + /** Parallelization can speedup your build significantly and is therefore highly recommended. */ + parallel?: boolean | { cache: boolean, workers: boolean | number }; + sourceMap?: boolean; + test?: Condition | Condition[]; + } + } + } + + namespace dependencies { + } + + namespace loader { + interface Loader extends Function { + (this: LoaderContext, source: string | Buffer, sourceMap?: RawSourceMap): string | Buffer | void | undefined; + + /** + * The order of chained loaders are always called from right to left. + * But, in some cases, loaders do not care about the results of the previous loader or the resource. + * They only care for metadata. The pitch method on the loaders is called from left to right before the loaders are called (from right to left). + * If a loader delivers a result in the pitch method the process turns around and skips the remaining loaders, + * continuing with the calls to the more left loaders. data can be passed between pitch and normal call. + */ + pitch?(remainingRequest: string, precedingRequest: string, data: any): any; + + /** + * By default, the resource file is treated as utf-8 string and passed as String to the loader. + * By setting raw to true the loader is passed the raw Buffer. + * Every loader is allowed to deliver its result as String or as Buffer. + * The compiler converts them between loaders. + */ + raw?: boolean; + } + + type loaderCallback = (err: Error | undefined | null, content?: string | Buffer, sourceMap?: RawSourceMap) => void; + + interface LoaderContext { + /** + * Loader API version. Currently 2. + * This is useful for providing backwards compatibility. + * Using the version you can specify custom logic or fallbacks for breaking changes. + */ + version: string; + + /** + * The directory of the module. Can be used as context for resolving other stuff. + * In the example: /abc because resource.js is in this directory + */ + context: string; + + /** + * The resolved request string. + * In the example: "/abc/loader1.js?xyz!/abc/node_modules/loader2/index.js!/abc/resource.js?rrr" + */ + request: string; + + /** + * A string or any object. The query of the request for the current loader. + */ + query: any; + + /** + * A data object shared between the pitch and the normal phase. + */ + data?: any; + + callback: loaderCallback; + + /** + * Make this loader async. + */ + async(): loaderCallback | undefined; + + /** + * Make this loader result cacheable. By default it's not cacheable. + * A cacheable loader must have a deterministic result, when inputs and dependencies haven't changed. + * This means the loader shouldn't have other dependencies than specified with this.addDependency. + * Most loaders are deterministic and cacheable. + */ + cacheable(flag?: boolean): void; + + /** + * loaders = [{request: string, path: string, query: string, module: function}] + * An array of all the loaders. It is writeable in the pitch phase. + * In the example: + * [ + * { request: "/abc/loader1.js?xyz", + * path: "/abc/loader1.js", + * query: "?xyz", + * module: [Function] + * }, + * { request: "/abc/node_modules/loader2/index.js", + * path: "/abc/node_modules/loader2/index.js", + * query: "", + * module: [Function] + * } + * ] + */ + loaders: any[]; + + /** + * The index in the loaders array of the current loader. + * In the example: in loader1: 0, in loader2: 1 + */ + loaderIndex: number; + + /** + * The resource part of the request, including query. + * In the example: "/abc/resource.js?rrr" + */ + resource: string; + + /** + * The resource file. + * In the example: "/abc/resource.js" + */ + resourcePath: string; + + /** + * The query of the resource. + * In the example: "?rrr" + */ + resourceQuery: string; + + /** + * Emit a warning. + */ + emitWarning(message: string | Error): void; + + /** + * Emit a error. + */ + emitError(message: string | Error): void; + + /** + * Execute some code fragment like a module. + * + * Don't use require(this.resourcePath), use this function to make loaders chainable! + * + */ + exec(code: string, filename: string): any; + + /** + * Resolve a request like a require expression. + */ + resolve(context: string, request: string, callback: (err: Error, result: string) => void): any; + + /** + * Resolve a request like a require expression. + */ + resolveSync(context: string, request: string): string; + + /** + * Adds a file as dependency of the loader result in order to make them watchable. + * For example, html-loader uses this technique as it finds src and src-set attributes. + * Then, it sets the url's for those attributes as dependencies of the html file that is parsed. + */ + addDependency(file: string): void; + + /** + * Adds a file as dependency of the loader result in order to make them watchable. + * For example, html-loader uses this technique as it finds src and src-set attributes. + * Then, it sets the url's for those attributes as dependencies of the html file that is parsed. + */ + dependency(file: string): void; + + /** + * Add a directory as dependency of the loader result. + */ + addContextDependency(directory: string): void; + + /** + * Remove all dependencies of the loader result. Even initial dependencies and these of other loaders. Consider using pitch. + */ + clearDependencies(): void; + + /** + * Pass values to the next loader. + * If you know what your result exports if executed as module, set this value here (as a only element array). + */ + value: any; + + /** + * Passed from the last loader. + * If you would execute the input argument as module, consider reading this variable for a shortcut (for performance). + */ + inputValue: any; + + /** + * The options passed to the Compiler. + */ + options: any; + + /** + * A boolean flag. It is set when in debug mode. + */ + debug: boolean; + + /** + * Should the result be minimized. + */ + minimize: boolean; + + /** + * Should a SourceMap be generated. + */ + sourceMap: boolean; + + /** + * Target of compilation. Passed from configuration options. + * Example values: "web", "node" + */ + target: 'web' | 'webworker' | 'async-node' | 'node' | 'electron-main' | 'electron-renderer' | 'node-webkit' | string; + + /** + * This boolean is set to true when this is compiled by webpack. + * + * Loaders were originally designed to also work as Babel transforms. + * Therefore if you write a loader that works for both, you can use this property to know if + * there is access to additional loaderContext and webpack features. + */ + webpack: boolean; + + /** + * Emit a file. This is webpack-specific. + */ + emitFile(name: string, content: Buffer | string, sourceMap: any): void; + + /** + * Access to the compilation's inputFileSystem property. + */ + fs: any; + + /** + * Hacky access to the Compilation object of webpack. + */ + _compilation: any; + + /** + * Hacky access to the Compiler object of webpack. + */ + _compiler: Compiler; + + /** + * Hacky access to the Module object being loaded. + */ + _module: any; + } + } + + /** @deprecated */ + namespace compiler { + /** @deprecated use webpack.Compiler */ + // tslint:disable-next-line:no-unnecessary-qualifier + type Compiler = webpack.Compiler; + + /** @deprecated use webpack.Compiler.Watching */ + type Watching = Compiler.Watching; + + /** @deprecated use webpack.Compiler.WatchOptions */ + + type WatchOptions = Compiler.WatchOptions; + + /** @deprecated use webpack.Stats */ + // tslint:disable-next-line:no-unnecessary-qualifier + type Stats = webpack.Stats; + + /** @deprecated use webpack.Stats.ToJsonOptions */ + type StatsOptions = Stats.ToJsonOptions; + + /** @deprecated use webpack.Stats.ToStringOptions */ + type StatsToStringOptions = Stats.ToStringOptions; + + /** @deprecated use webpack.Compiler.Handler */ + type CompilerCallback = Compiler.Handler; + } + + /** @deprecated use webpack.Options.Performance */ + type PerformanceOptions = Options.Performance; + /** @deprecated use webpack.Options.WatchOptions */ + type WatchOptions = Options.WatchOptions; + /** @deprecated use webpack.EvalSourceMapDevToolPlugin.Options */ + type EvalSourceMapDevToolPluginOptions = EvalSourceMapDevToolPlugin.Options; + /** @deprecated use webpack.SourceMapDevToolPlugin.Options */ + type SourceMapDevToolPluginOptions = SourceMapDevToolPlugin.Options; + /** @deprecated use webpack.optimize.UglifyJsPlugin.CommentFilter */ + type UglifyCommentFunction = optimize.UglifyJsPlugin.CommentFilter; + /** @deprecated use webpack.optimize.UglifyJsPlugin.Options */ + type UglifyPluginOptions = optimize.UglifyJsPlugin.Options; +} \ No newline at end of file diff --git a/types/webpack/v3/package.json b/types/webpack/v3/package.json new file mode 100644 index 0000000000..59c231c54c --- /dev/null +++ b/types/webpack/v3/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "dependencies": { + "source-map": "^0.6.0" + } +} diff --git a/types/webpack/v3/tsconfig.json b/types/webpack/v3/tsconfig.json new file mode 100644 index 0000000000..a6671e38b4 --- /dev/null +++ b/types/webpack/v3/tsconfig.json @@ -0,0 +1,26 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../../", + "typeRoots": [ + "../../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "paths": { + "webpack": ["webpack/v3"] + } + }, + "files": [ + "index.d.ts", + "webpack-tests.ts" + ] +} \ No newline at end of file diff --git a/types/webpack/v3/tslint.json b/types/webpack/v3/tslint.json new file mode 100644 index 0000000000..b4b47a0378 --- /dev/null +++ b/types/webpack/v3/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +} diff --git a/types/webpack/v3/webpack-tests.ts b/types/webpack/v3/webpack-tests.ts new file mode 100644 index 0000000000..f56dbb84b6 --- /dev/null +++ b/types/webpack/v3/webpack-tests.ts @@ -0,0 +1,667 @@ +import webpack = require('webpack'); +import { RawSourceMap } from 'source-map'; + +const { + optimize, +} = webpack; + +let plugins: webpack.Plugin[]; + +/** + * Plugins + */ + +/** + * optimize + */ + +const { + AggressiveMergingPlugin, +} = optimize; + +plugins = [ + new AggressiveMergingPlugin(), + new AggressiveMergingPlugin({}), + new AggressiveMergingPlugin({ + entryChunkMultiplicator: 10, + minSizeReduce: 1.5, + moveToParents: false, + }), +]; + +let configuration: webpack.Configuration; +let rule: webpack.Rule; +let plugin: webpack.Plugin; +declare const __dirname: string; + +// +// https://webpack.github.io/docs/using-loaders.html +// + +configuration = { + module: { + loaders: [ + { test: /\.jade$/, loader: "jade" }, + // => "jade" loader is used for ".jade" files + + { test: /\.css$/, loader: "style!css" }, + // => "style" and "css" loader is used for ".css" files + // Alternative syntax: + { test: /\.css$/, loaders: ["style", "css"] }, + ] + } +}; + +rule = { test: /\.png$/, loader: "url-loader?mimetype=image/png" }; + +rule = { + test: /\.png$/, + loader: "url-loader", + query: { mimetype: "image/png" } +}; + +// +// http://webpack.github.io/docs/tutorials/getting-started/ +// + +configuration = { + entry: "./entry.js", + output: { + path: __dirname, + filename: "bundle.js" + }, + module: { + loaders: [ + { test: /\.css$/, loader: "style!css" } + ] + } +}; + +// +// https://webpack.js.org/configuration/entry-context/#dynamic-entry +// + +configuration = { + entry: () => './demo' +}; + +configuration = { + entry: () => ['./demo', './demo2'] +}; + +configuration = { + entry: () => new Promise((resolve) => resolve('./demo')) +}; + +configuration = { + entry: () => new Promise((resolve) => resolve(['./demo', './demo2'])) +}; + +// +// https://webpack.github.io/docs/code-splitting.html +// + +configuration = { + entry: { + app: "./app.js", + vendor: ["jquery", "underscore"], + }, + output: { + filename: "bundle.js" + }, + plugins: [ + new webpack.optimize.CommonsChunkPlugin({ + name: "vendor", + filename: "vendor.bundle.js", + }), + ] +}; + +configuration = { + entry: { a: "./a", b: "./b" }, + output: { filename: "[name].js" }, + plugins: [new webpack.optimize.CommonsChunkPlugin({ name: "init.js" })] +}; + +// +// https://webpack.github.io/docs/stylesheets.html +// + +configuration = { + // ... + module: { + loaders: [ + { test: /\.css$/, loader: "style-loader!css-loader" } + ] + } +}; + +// +// https://webpack.github.io/docs/optimization.html +// + +configuration = { + entry: { + p1: "./page1", + p2: "./page2", + p3: "./page3" + }, + output: { + filename: "[name].entry.chunk.js" + } +}; + +const CommonsChunkPlugin = webpack.optimize.CommonsChunkPlugin; +configuration = { + entry: { + p1: "./page1", + p2: "./page2", + p3: "./page3" + }, + output: { + filename: "[name].entry.chunk.js" + }, + plugins: [ + new CommonsChunkPlugin({ name: "commons.chunk.js" }) + ] +}; + +configuration = { + entry: { + p1: "./page1", + p2: "./page2", + p3: "./page3", + ap1: "./admin/page1", + ap2: "./admin/page2" + }, + output: { + filename: "[name].js" + }, +}; +//