UNPKG

1.65 kBJavaScriptView Raw
1"use strict";
2
3exports.__esModule = true;
4exports.default = void 0;
5
6var _webpack = _interopRequireDefault(require("webpack"));
7
8function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
10function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
11
12// Webpack plugin that makes Styleguidist config available for Styleguidist webpack loaders.
13// It will be available as `this._styleguidist`.
14//
15// Other working in webpack 2 way is to use LoaderOptionsPlugin, but it has problems.
16// See this issue for details: https://github.com/styleguidist/react-styleguidist/issues/328
17class StyleguidistOptionsPlugin {
18 constructor(options) {
19 _defineProperty(this, "options", void 0);
20
21 _defineProperty(this, "pluginFunc", (context, module) => {
22 if (!module.resource) {
23 return;
24 }
25
26 context._styleguidist = this.options;
27 });
28
29 _defineProperty(this, "plugin", compil => {
30 // Webpack 5
31
32 /* istanbul ignore next */
33 if ('NormalModule' in _webpack.default) {
34 // @ts-ignore
35 _webpack.default.NormalModule.getCompilationHooks(compil).loader.tap('StyleguidistOptionsPlugin', this.pluginFunc);
36
37 return;
38 } // Webpack 4
39
40
41 compil.hooks.normalModuleLoader.tap('StyleguidistOptionsPlugin', this.pluginFunc);
42 });
43
44 this.options = options;
45 }
46
47 apply(compiler) {
48 compiler.hooks.compilation.tap('StyleguidistOptionsPlugin', this.plugin);
49 }
50
51}
52
53exports.default = StyleguidistOptionsPlugin;
\No newline at end of file