source: imaps-frontend/node_modules/webpack/lib/library/JsonpLibraryPlugin.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 4 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 2.6 KB
Line 
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5
6"use strict";
7
8const { ConcatSource } = require("webpack-sources");
9const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
10
11/** @typedef {import("webpack-sources").Source} Source */
12/** @typedef {import("../../declarations/WebpackOptions").LibraryOptions} LibraryOptions */
13/** @typedef {import("../../declarations/WebpackOptions").LibraryType} LibraryType */
14/** @typedef {import("../Chunk")} Chunk */
15/** @typedef {import("../Compilation").ChunkHashContext} ChunkHashContext */
16/** @typedef {import("../Compiler")} Compiler */
17/** @typedef {import("../javascript/JavascriptModulesPlugin").RenderContext} RenderContext */
18/** @typedef {import("../util/Hash")} Hash */
19/** @template T @typedef {import("./AbstractLibraryPlugin").LibraryContext<T>} LibraryContext<T> */
20
21/**
22 * @typedef {object} JsonpLibraryPluginOptions
23 * @property {LibraryType} type
24 */
25
26/**
27 * @typedef {object} JsonpLibraryPluginParsed
28 * @property {string} name
29 */
30
31/**
32 * @typedef {JsonpLibraryPluginParsed} T
33 * @extends {AbstractLibraryPlugin<JsonpLibraryPluginParsed>}
34 */
35class JsonpLibraryPlugin extends AbstractLibraryPlugin {
36 /**
37 * @param {JsonpLibraryPluginOptions} options the plugin options
38 */
39 constructor(options) {
40 super({
41 pluginName: "JsonpLibraryPlugin",
42 type: options.type
43 });
44 }
45
46 /**
47 * @param {LibraryOptions} library normalized library option
48 * @returns {T | false} preprocess as needed by overriding
49 */
50 parseOptions(library) {
51 const { name } = library;
52 if (typeof name !== "string") {
53 throw new Error(
54 `Jsonp library name must be a simple string. ${AbstractLibraryPlugin.COMMON_LIBRARY_NAME_MESSAGE}`
55 );
56 }
57 const _name = /** @type {string} */ (name);
58 return {
59 name: _name
60 };
61 }
62
63 /**
64 * @param {Source} source source
65 * @param {RenderContext} renderContext render context
66 * @param {LibraryContext<T>} libraryContext context
67 * @returns {Source} source with library export
68 */
69 render(source, { chunk }, { options, compilation }) {
70 const name = compilation.getPath(options.name, {
71 chunk
72 });
73 return new ConcatSource(`${name}(`, source, ")");
74 }
75
76 /**
77 * @param {Chunk} chunk the chunk
78 * @param {Hash} hash hash
79 * @param {ChunkHashContext} chunkHashContext chunk hash context
80 * @param {LibraryContext<T>} libraryContext context
81 * @returns {void}
82 */
83 chunkHash(chunk, hash, chunkHashContext, { options, compilation }) {
84 hash.update("JsonpLibraryPlugin");
85 hash.update(compilation.getPath(options.name, { chunk }));
86 }
87}
88
89module.exports = JsonpLibraryPlugin;
Note: See TracBrowser for help on using the repository browser.