Last active
January 3, 2020 20:58
-
-
Save Legends/52f249217aa8ac04385ea28a9829a9ef to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //--> WebpackCompilation is an exported class inside Compilation.js | |
| /** @typedef {import("webpack/lib/Compilation.js")} WebpackCompilation */ | |
| //--> WebpackCompiler is an exported class inside Compiler.js | |
| /** @typedef {import("webpack/lib/Compiler.js")} WebpackCompiler */ | |
| //--> WebpackOptions is an exported interface inside WebpackOptions.d.ts file | |
| /** @typedef {import("webpack/declarations/WebpackOptions").WebpackOptions} WebpackOptions */ | |
| /* ###################################### EXAMPLES #################################################*/ | |
| // *************************************** LOCAL VARIABLE | |
| /** @type {WebpackOptions} */ | |
| let wpc = compiler.options; | |
| // *************************************** FUNCTION PARAMETER | |
| /** | |
| * | |
| * @param {WebpackCompiler} compiler | |
| */ | |
| apply(compiler) {...} | |
| // *************************************** INLINE DECLARATION OF PARAMETER | |
| // or inline: | |
| compiler.hooks.run.tap('xxxx',/** @param {WebpackCompilation} compilation */ compilation => { | |
| console.log("run run run run run " + Date.now()); | |
| let com = compiler;// compiler.options | |
| debugger; | |
| }); | |
| // *************************************** PROMISE DECLARATION | |
| /** @type Promise<string> */ | |
| let compilationPromise; | |
| // *************************************** VOID FUNCTION | |
| /** | |
| * Hook into the webpack emit phase | |
| * @param {WebpackCompilation} compilation | |
| * @param {() => void} callback | |
| */ | |
| (compilation, callback) => {...} | |
| // *************************************** MULTIPLE TYPES POSSIBLE | |
| /** | |
| * Evaluates the child compilation result | |
| * @param {WebpackCompilation} compilation | |
| * @param {string} source | |
| * @returns {Promise<string | (() => string | Promise<string>)>} | |
| */ | |
| evaluateCompilationResult (compilation, source) {..} | |
| // *************************************** INLINE DEFINITION OF CUSTOM OBJECT PARAMETER | |
| /** | |
| * This function renders the actual html by executing the template function | |
| * | |
| * @param {(templateParameters) => string | Promise<string>} templateFunction | |
| * @param {{ | |
| publicPath: string, | |
| js: Array<string>, | |
| css: Array<string>, | |
| manifest?: string, | |
| favicon?: string | |
| }} assets | |
| * @param {{ | |
| headTags: HtmlTagObject[], | |
| bodyTags: HtmlTagObject[] | |
| }} assetTags | |
| * @param {WebpackCompilation} compilation | |
| * | |
| * @returns Promise<string> | |
| */ | |
| executeTemplate (templateFunction, assets, assetTags, compilation) {...} | |
| /** | |
| * Html Post processing | |
| * | |
| * @param {any} html | |
| * The input html | |
| * @param {any} assets | |
| * @param {{ | |
| headTags: HtmlTagObject[], | |
| bodyTags: HtmlTagObject[] | |
| }} assetTags | |
| * The asset tags to inject | |
| * | |
| * @returns {Promise<string>} | |
| */ | |
| postProcessHtml (html, assets, assetTags) {...} | |
| // *************************************** INLINE DEFINITION OF CUSTOM FUNCTION PARAMETER | |
| /** | |
| * Helper to sort chunks | |
| * @param {string[]} entryNames | |
| * @param {string|((entryNameA: string, entryNameB: string) => number)} sortMode | |
| * @param {WebpackCompilation} compilation | |
| */ | |
| sortEntryChunks (entryNames, sortMode, compilation) {..} | |
| // *************************************** DEFINE PREDEFINED VALUE AS POSSIBLE PARAMETER TYPE (SCND PARAMETER) | |
| /** | |
| * Return all chunks from the compilation result which match the exclude and include filters | |
| * @param {any} chunks | |
| * @param {string[]|'all'} includedChunks | |
| * @param {string[]} excludedChunks | |
| */ | |
| filterChunks (chunks, includedChunks, excludedChunks) {...} | |
| // *************************************** PARAMETER AS ARRAY OF TYPES | |
| /** | |
| * Generate all tags script for the given file paths | |
| * @param {Array<string>} jsAssets | |
| * @returns {Array<HtmlTagObject>} | |
| */ | |
| generatedScriptTags (jsAssets) {..} | |
| // *************************************** ATTRIBUTE AS PARAMETER | |
| /** | |
| * Generate an optional base tag | |
| * @param { false | |
| | string | |
| | {[attributeName: string]: string} // attributes e.g. { href:"http://example.com/page.html" target:"_blank" } | |
| } baseOption | |
| * @returns {Array<HtmlTagObject>} | |
| */ | |
| generateBaseTag (baseOption) { | |
| if (baseOption === false) {...} } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment