diff --git a/types/extract-text-webpack-plugin/extract-text-webpack-plugin-tests.ts b/types/extract-text-webpack-plugin/extract-text-webpack-plugin-tests.ts index ca992ea3ef..06fc528cff 100644 --- a/types/extract-text-webpack-plugin/extract-text-webpack-plugin-tests.ts +++ b/types/extract-text-webpack-plugin/extract-text-webpack-plugin-tests.ts @@ -1,10 +1,7 @@ -import { optimize, Configuration, Plugin } from 'webpack' - -import * as ExtractTextPlugin from 'extract-text-webpack-plugin' - - -let configuration: Configuration +import webpack = require('webpack'); +import ExtractTextPlugin = require('extract-text-webpack-plugin'); +let configuration: webpack.Configuration; configuration = { // The standard entry point and output config @@ -58,7 +55,7 @@ configuration = { configuration = { // ... plugins: [ - new optimize.CommonsChunkPlugin({ + new webpack.optimize.CommonsChunkPlugin({ name: "commons", filename: "commons.js", }), @@ -85,15 +82,15 @@ configuration = { }; // multiple extract instances -let extractCSS = new ExtractTextPlugin('stylesheets/[name].css'); -let extractLESS = new ExtractTextPlugin('stylesheets/[name].less'); +const extractCSS: ExtractTextPlugin = new ExtractTextPlugin('stylesheets/[name].css'); +const extractLESS: ExtractTextPlugin = new ExtractTextPlugin('stylesheets/[name].less'); configuration = { // ... module: { rules: [ - { test: /\.scss$/i, use: extractCSS.extract(['css','sass']) }, - { test: /\.less$/i, use: extractLESS.extract(['css','less']) }, + { test: /\.scss$/i, use: extractCSS.extract(['css', 'sass']) }, + { test: /\.less$/i, use: extractLESS.extract(['css', 'less']) }, ] }, plugins: [ diff --git a/types/extract-text-webpack-plugin/index.d.ts b/types/extract-text-webpack-plugin/index.d.ts index 0897d7b594..962698568a 100644 --- a/types/extract-text-webpack-plugin/index.d.ts +++ b/types/extract-text-webpack-plugin/index.d.ts @@ -1,49 +1,56 @@ -// Type definitions for extract-text-webpack-plugin 2.1.0 +// Type definitions for extract-text-webpack-plugin 3.0 // Project: https://github.com/webpack-contrib/extract-text-webpack-plugin // Definitions by: flying-sheep , kayo // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -import { Plugin, OldLoader, NewLoader } from 'webpack' +import webpack = require('webpack'); + +export = ExtractTextPlugin; /** * extract-text-webpack-plugin has no support for .options instead of .query yet. * See https://github.com/webpack/extract-text-webpack-plugin/issues/281 */ -type Loader = string | OldLoader | NewLoader - -interface ExtractPluginOptions { - /** the filename of the result file. May contain `[name]`, `[id]` and `[contenthash]` */ - filename: string - /** extract from all additional chunks too (by default it extracts only from the initial chunk(s)) */ - allChunks?: boolean - /** disables the plugin */ - disable?: boolean - /** Unique ident for this plugin instance. (For advanced usage only, by default automatically generated) */ - id?: string -} - -interface ExtractOptions { - /** the loader(s) that should be used for converting the resource to a css exporting module */ - use: Loader | Loader[] - /** the loader(s) that should be used when the css is not extracted (i.e. in an additional chunk when `allChunks: false`) */ - fallback?: Loader | Loader[] - /** override the `publicPath` setting for this loader */ - publicPath?: string -} +type Loader = string | webpack.OldLoader | webpack.NewLoader; /** * Use an `ExtractTextPlugin` instance and a loader returned by `extract` in concert to write files to disk instead of loading them into others. * Usage example at https://github.com/webpack/extract-text-webpack-plugin#usage-example-with-css */ -interface ExtractTextPlugin extends Plugin { +declare class ExtractTextPlugin extends webpack.Plugin { /** Create a plugin instance defining the extraction target file(s) for the files loaded by `extract` */ - new (options: string | ExtractPluginOptions): ExtractTextPlugin + constructor(options: string | ExtractTextPlugin.PluginOptions); /** - * Creates an extracting loader from an existing loader. + * Creates an extracting loader from an existing loader (static). * Use the resulting loader in `module.rules`/`module.loaders`. + * @see {@link https://www.npmjs.com/package/extract-text-webpack-plugin#extract} */ - extract: (loader: Loader | Loader[] | ExtractOptions) => Loader[] + static extract: (loader: Loader | Loader[] | ExtractTextPlugin.LoaderOptions) => Loader[]; + /** + * Creates an extracting loader from an existing loader (instance). + * Use the resulting loader in `module.rules`/`module.loaders`. + * @see {@link https://www.npmjs.com/package/extract-text-webpack-plugin#multiple-instances} + */ + extract: (loader: Loader | Loader[] | ExtractTextPlugin.LoaderOptions) => Loader[]; } -declare const extractTextPlugin: ExtractTextPlugin -export = extractTextPlugin +declare namespace ExtractTextPlugin { + interface PluginOptions { + /** the filename of the result file. May contain `[name]`, `[id]` and `[contenthash]` */ + filename: string; + /** extract from all additional chunks too (by default it extracts only from the initial chunk(s)) */ + allChunks?: boolean; + /** disables the plugin */ + disable?: boolean; + /** Unique ident for this plugin instance. (For advanced usage only, by default automatically generated) */ + id?: string; + } + interface LoaderOptions { + /** the loader(s) that should be used for converting the resource to a css exporting module */ + use: Loader | Loader[]; + /** the loader(s) that should be used when the css is not extracted (i.e. in an additional chunk when `allChunks: false`) */ + fallback?: Loader | Loader[]; + /** override the `publicPath` setting for this loader */ + publicPath?: string; + } +} diff --git a/types/extract-text-webpack-plugin/tsconfig.json b/types/extract-text-webpack-plugin/tsconfig.json index b5e248c21d..af41789949 100644 --- a/types/extract-text-webpack-plugin/tsconfig.json +++ b/types/extract-text-webpack-plugin/tsconfig.json @@ -19,4 +19,4 @@ "index.d.ts", "extract-text-webpack-plugin-tests.ts" ] -} \ No newline at end of file +} diff --git a/types/extract-text-webpack-plugin/tslint.json b/types/extract-text-webpack-plugin/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/extract-text-webpack-plugin/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }