Last change
on this file since ceaed42 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.2 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 |
|
---|
8 | const createSchemaValidation = require("../util/create-schema-validation");
|
---|
9 | const JsonGenerator = require("./JsonGenerator");
|
---|
10 | const JsonParser = require("./JsonParser");
|
---|
11 |
|
---|
12 | /** @typedef {import("../Compiler")} Compiler */
|
---|
13 |
|
---|
14 | const validate = createSchemaValidation(
|
---|
15 | require("../../schemas/plugins/JsonModulesPluginParser.check.js"),
|
---|
16 | () => require("../../schemas/plugins/JsonModulesPluginParser.json"),
|
---|
17 | {
|
---|
18 | name: "Json Modules Plugin",
|
---|
19 | baseDataPath: "parser"
|
---|
20 | }
|
---|
21 | );
|
---|
22 |
|
---|
23 | class JsonModulesPlugin {
|
---|
24 | /**
|
---|
25 | * Apply the plugin
|
---|
26 | * @param {Compiler} compiler the compiler instance
|
---|
27 | * @returns {void}
|
---|
28 | */
|
---|
29 | apply(compiler) {
|
---|
30 | compiler.hooks.compilation.tap(
|
---|
31 | "JsonModulesPlugin",
|
---|
32 | (compilation, { normalModuleFactory }) => {
|
---|
33 | normalModuleFactory.hooks.createParser
|
---|
34 | .for("json")
|
---|
35 | .tap("JsonModulesPlugin", parserOptions => {
|
---|
36 | validate(parserOptions);
|
---|
37 |
|
---|
38 | return new JsonParser(parserOptions);
|
---|
39 | });
|
---|
40 | normalModuleFactory.hooks.createGenerator
|
---|
41 | .for("json")
|
---|
42 | .tap("JsonModulesPlugin", () => {
|
---|
43 | return new JsonGenerator();
|
---|
44 | });
|
---|
45 | }
|
---|
46 | );
|
---|
47 | }
|
---|
48 | }
|
---|
49 |
|
---|
50 | module.exports = JsonModulesPlugin;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.