source: imaps-frontend/node_modules/webpack/lib/json/JsonModulesPlugin.js@ 79a0317

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

F4 Finalna Verzija

  • Property mode set to 100644
File size: 1.5 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 { JSON_MODULE_TYPE } = require("../ModuleTypeConstants");
9const createSchemaValidation = require("../util/create-schema-validation");
10const JsonGenerator = require("./JsonGenerator");
11const JsonParser = require("./JsonParser");
12
13/** @typedef {import("../Compiler")} Compiler */
14/** @typedef {Record<string, any>} RawJsonData */
15
16const validate = createSchemaValidation(
17 require("../../schemas/plugins/JsonModulesPluginParser.check.js"),
18 () => require("../../schemas/plugins/JsonModulesPluginParser.json"),
19 {
20 name: "Json Modules Plugin",
21 baseDataPath: "parser"
22 }
23);
24
25const PLUGIN_NAME = "JsonModulesPlugin";
26
27/**
28 * The JsonModulesPlugin is the entrypoint plugin for the json modules feature.
29 * It adds the json module type to the compiler and registers the json parser and generator.
30 */
31class JsonModulesPlugin {
32 /**
33 * Apply the plugin
34 * @param {Compiler} compiler the compiler instance
35 * @returns {void}
36 */
37 apply(compiler) {
38 compiler.hooks.compilation.tap(
39 PLUGIN_NAME,
40 (compilation, { normalModuleFactory }) => {
41 normalModuleFactory.hooks.createParser
42 .for(JSON_MODULE_TYPE)
43 .tap(PLUGIN_NAME, parserOptions => {
44 validate(parserOptions);
45
46 return new JsonParser(parserOptions);
47 });
48 normalModuleFactory.hooks.createGenerator
49 .for(JSON_MODULE_TYPE)
50 .tap(PLUGIN_NAME, () => new JsonGenerator());
51 }
52 );
53 }
54}
55
56module.exports = JsonModulesPlugin;
Note: See TracBrowser for help on using the repository browser.