diff --git a/types/script-ext-html-webpack-plugin/index.d.ts b/types/script-ext-html-webpack-plugin/index.d.ts new file mode 100644 index 0000000000..636ac550e5 --- /dev/null +++ b/types/script-ext-html-webpack-plugin/index.d.ts @@ -0,0 +1,79 @@ +// Type definitions for script-ext-html-webpack-plugin 2.1 +// Project: https://github.com/numical/script-ext-html-webpack-plugin +// Definitions by: Dave Cardwell +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +import { Plugin } from "webpack"; + +export = ScriptExtHtmlWebpackPlugin; + +declare class ScriptExtHtmlWebpackPlugin extends Plugin { + constructor(options?: ScriptExtHtmlWebpackPlugin.Options); +} + +type ScriptMatchingPatternBase = + | string + | RegExp + | ReadonlyArray; + +interface ScriptMatchingPatternHash { + test: ScriptMatchingPatternBase; +} + +type ScriptMatchingPattern = + | ScriptMatchingPatternBase + | ScriptMatchingPatternHash; + +type ScriptMatchingPatternPre = + | ScriptMatchingPatternBase + | ScriptMatchingPatternHash & { + chunks?: "initial" | "async" | "all"; + }; + +interface Custom { + test: ScriptMatchingPattern; + attribute: string; + value?: string; +} + +declare namespace ScriptExtHtmlWebpackPlugin { + interface Options { + /** + * scripts that should be inlined in the html (default: `[]`) + */ + inline?: ScriptMatchingPattern; + /** + * script names that should have no attribute (default: `[]`) + */ + sync?: ScriptMatchingPattern; + /** + * script names that should have an async attribute (default: `[]`) + */ + async?: ScriptMatchingPattern; + /** + * script names that should have a defer attribute (default: `[]`) + */ + defer?: ScriptMatchingPattern; + /** + * the default attribute to set - 'sync' actually results in no attribute (default: 'sync') + */ + defaultAttribute?: "sync" | "async" | "defer"; + /** + * script names that should have a type="module" attribute (default: `[]`) + */ + module?: ScriptMatchingPattern; + /** + * scripts that should have accompanying preload resource hints (default: `[]`) + */ + preload?: ScriptMatchingPatternPre; + /** + * scripts that should have accompanying prefetch resource hints (default: `[]`) + */ + prefetch?: ScriptMatchingPatternPre; + /** + * scripts that should have a custom attribute(s) added, the attribute(s), and the value(s) + */ + custom?: Custom | Custom[]; + } +} diff --git a/types/script-ext-html-webpack-plugin/script-ext-html-webpack-plugin-tests.ts b/types/script-ext-html-webpack-plugin/script-ext-html-webpack-plugin-tests.ts new file mode 100644 index 0000000000..84c42b2ae9 --- /dev/null +++ b/types/script-ext-html-webpack-plugin/script-ext-html-webpack-plugin-tests.ts @@ -0,0 +1,112 @@ +import ScriptExtHtmlWebpackPlugin = require("script-ext-html-webpack-plugin"); + +new ScriptExtHtmlWebpackPlugin(); +new ScriptExtHtmlWebpackPlugin({}); + +new ScriptExtHtmlWebpackPlugin({ + inline: "string", + sync: "string", + async: "string", + defer: "string", + module: "string", + preload: "string", + prefetch: "string" +}); + +new ScriptExtHtmlWebpackPlugin({ + inline: ["array"], + sync: ["array"], + async: ["array"], + defer: ["array"], + module: ["array"], + preload: ["array"], + prefetch: ["array"] +}); + +new ScriptExtHtmlWebpackPlugin({ + inline: /regexp/, + sync: /regexp/, + async: /regexp/, + defer: /regexp/, + module: /regexp/, + preload: /regexp/, + prefetch: /regexp/ +}); + +new ScriptExtHtmlWebpackPlugin({ + inline: { test: "string" }, + sync: { test: "string" }, + async: { test: "string" }, + defer: { test: "string" }, + module: { test: "string" }, + preload: { test: "string" }, + prefetch: { test: "string" } +}); + +new ScriptExtHtmlWebpackPlugin({ + inline: { test: ["array"] }, + sync: { test: ["array"] }, + async: { test: ["array"] }, + defer: { test: ["array"] }, + module: { test: ["array"] }, + preload: { test: ["array"] }, + prefetch: { test: ["array"] } +}); + +new ScriptExtHtmlWebpackPlugin({ + inline: { test: /regexp/ }, + sync: { test: /regexp/ }, + async: { test: /regexp/ }, + defer: { test: /regexp/ }, + module: { test: /regexp/ }, + preload: { test: /regexp/ }, + prefetch: { test: /regexp/ } +}); + +new ScriptExtHtmlWebpackPlugin({ + preload: { test: "string", chunks: "initial" }, + prefetch: { test: "string", chunks: "initial" } +}); + +new ScriptExtHtmlWebpackPlugin({ + preload: { test: "string", chunks: "async" }, + prefetch: { test: "string", chunks: "async" } +}); + +new ScriptExtHtmlWebpackPlugin({ + preload: { test: "string", chunks: "all" }, + prefetch: { test: "string", chunks: "all" } +}); + +new ScriptExtHtmlWebpackPlugin({ defaultAttribute: "sync" }); +new ScriptExtHtmlWebpackPlugin({ defaultAttribute: "async" }); +new ScriptExtHtmlWebpackPlugin({ defaultAttribute: "defer" }); + +new ScriptExtHtmlWebpackPlugin({ + custom: { + test: "string", + attribute: "string" + } +}); + +new ScriptExtHtmlWebpackPlugin({ + custom: { + test: ["array"], + attribute: "string", + value: "string" + } +}); + +new ScriptExtHtmlWebpackPlugin({ + custom: [ + { + test: /regexp/, + attribute: "string" + }, + { + test: "string", + attribute: "string", + value: "string" + } + ] +}); diff --git a/types/script-ext-html-webpack-plugin/tsconfig.json b/types/script-ext-html-webpack-plugin/tsconfig.json new file mode 100644 index 0000000000..32c8e618e3 --- /dev/null +++ b/types/script-ext-html-webpack-plugin/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es6"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": ["../"], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": ["index.d.ts", "script-ext-html-webpack-plugin-tests.ts"] +} diff --git a/types/script-ext-html-webpack-plugin/tslint.json b/types/script-ext-html-webpack-plugin/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/script-ext-html-webpack-plugin/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }