1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- "use strict";
- const { ConcatSource } = require("webpack-sources");
- const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
- class JsonpLibraryPlugin extends AbstractLibraryPlugin {
-
- constructor(options) {
- super({
- pluginName: "JsonpLibraryPlugin",
- type: options.type
- });
- }
-
- parseOptions(library) {
- const { name } = library;
- if (typeof name !== "string") {
- throw new Error(
- `Jsonp library name must be a simple string. ${AbstractLibraryPlugin.COMMON_LIBRARY_NAME_MESSAGE}`
- );
- }
- const _name = (name);
- return {
- name: _name
- };
- }
-
- render(source, { chunk }, { options, compilation }) {
- const name = compilation.getPath(options.name, {
- chunk
- });
- return new ConcatSource(`${name}(`, source, ")");
- }
-
- chunkHash(chunk, hash, chunkHashContext, { options, compilation }) {
- hash.update("JsonpLibraryPlugin");
- hash.update(compilation.getPath(options.name, { chunk }));
- }
- }
- module.exports = JsonpLibraryPlugin;
|