-
Notifications
You must be signed in to change notification settings - Fork 307
Expand file tree
/
Copy pathindex.ts
More file actions
99 lines (86 loc) · 2.53 KB
/
index.ts
File metadata and controls
99 lines (86 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/* ============================================================================
* Copyright (c) Palo Alto Networks
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* ========================================================================== */
import path from "path";
import type { Plugin, ConfigureWebpackUtils } from "@docusaurus/types";
import type { Configuration } from "webpack";
export default function docusaurusThemeOpenAPI(): Plugin<void> {
return {
name: "docusaurus-theme-openapi",
getClientModules() {
return [
require.resolve(
path.join(__dirname, "..", "lib", "theme", "styles.scss")
),
];
},
getThemePath() {
return path.join(__dirname, "..", "lib", "theme");
},
getTypeScriptThemePath() {
return path.resolve(__dirname, "..", "src", "theme");
},
configureWebpack(
config: Configuration,
isServer: boolean,
utils: ConfigureWebpackUtils
): Configuration {
const { getStyleLoaders, currentBundler } = utils;
const fakerAlias = {
"@faker-js/faker": path.resolve(
__dirname,
"..",
"src",
"shims",
"faker.ts"
),
};
const ignoreFaker = new currentBundler.instance.IgnorePlugin({
resourceRegExp: /^@faker-js\/faker$/,
});
const existingRules: any[] = config.module?.rules ?? [];
const hasSassRule = existingRules.some(
(r) => String(r.test) === String(/\.s[ca]ss$/)
);
const baseConfig: Configuration = {
resolve: {
alias: fakerAlias,
fallback: {
buffer: require.resolve("buffer/"),
},
},
plugins: [
ignoreFaker,
new currentBundler.instance.ProvidePlugin({
process: require.resolve("process/browser"),
Buffer: ["buffer", "Buffer"],
}),
],
};
if (!hasSassRule) {
return {
...baseConfig,
module: {
rules: [
{
test: /\.s[ac]ss$/,
include: path.resolve(__dirname, "..", "lib", "theme"),
use: [
...getStyleLoaders(isServer, {}),
{
loader: require.resolve("sass-loader"),
options: {},
},
],
},
],
},
};
}
return baseConfig;
},
};
}