2017-11-12 01:48:29 +08:00
|
|
|
/*
|
|
|
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
|
|
Author Tobias Koppers @sokra
|
|
|
|
*/
|
2018-07-30 23:08:51 +08:00
|
|
|
|
2017-11-12 01:48:29 +08:00
|
|
|
"use strict";
|
|
|
|
|
2021-04-16 21:35:18 +08:00
|
|
|
const createSchemaValidation = require("../util/create-schema-validation");
|
2018-01-24 06:09:26 +08:00
|
|
|
const JsonGenerator = require("./JsonGenerator");
|
2018-07-30 23:08:51 +08:00
|
|
|
const JsonParser = require("./JsonParser");
|
2017-12-07 03:37:58 +08:00
|
|
|
|
2019-10-11 21:46:57 +08:00
|
|
|
/** @typedef {import("../Compiler")} Compiler */
|
2018-11-03 04:05:46 +08:00
|
|
|
|
2021-04-16 21:35:18 +08:00
|
|
|
const validate = createSchemaValidation(
|
|
|
|
require("../../schemas/plugins/JsonModulesPluginParser.check.js"),
|
|
|
|
() => require("../../schemas/plugins/JsonModulesPluginParser.json"),
|
|
|
|
{
|
|
|
|
name: "Json Modules Plugin",
|
|
|
|
baseDataPath: "parser"
|
|
|
|
}
|
2019-12-02 23:37:55 +08:00
|
|
|
);
|
2019-11-29 01:12:11 +08:00
|
|
|
|
2017-11-12 01:48:29 +08:00
|
|
|
class JsonModulesPlugin {
|
2018-11-03 04:05:46 +08:00
|
|
|
/**
|
|
|
|
* Apply the plugin
|
|
|
|
* @param {Compiler} compiler the compiler instance
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2017-11-12 01:48:29 +08:00
|
|
|
apply(compiler) {
|
2018-02-25 09:00:20 +08:00
|
|
|
compiler.hooks.compilation.tap(
|
|
|
|
"JsonModulesPlugin",
|
|
|
|
(compilation, { normalModuleFactory }) => {
|
|
|
|
normalModuleFactory.hooks.createParser
|
|
|
|
.for("json")
|
2019-11-29 01:12:11 +08:00
|
|
|
.tap("JsonModulesPlugin", parserOptions => {
|
2021-04-16 21:35:18 +08:00
|
|
|
validate(parserOptions);
|
2019-11-29 01:12:11 +08:00
|
|
|
|
|
|
|
return new JsonParser(parserOptions);
|
2018-02-25 09:00:20 +08:00
|
|
|
});
|
|
|
|
normalModuleFactory.hooks.createGenerator
|
|
|
|
.for("json")
|
|
|
|
.tap("JsonModulesPlugin", () => {
|
|
|
|
return new JsonGenerator();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
2017-11-12 01:48:29 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = JsonModulesPlugin;
|