-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathwebpack.config.ts
More file actions
61 lines (55 loc) · 1.88 KB
/
webpack.config.ts
File metadata and controls
61 lines (55 loc) · 1.88 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
import type { Configuration } from 'webpack';
import { merge } from 'webpack-merge';
import grafanaConfig, { type Env } from './.config/webpack/webpack.config';
import path from 'path';
const htmlGraphicsDeclarationsPath = path.resolve(__dirname, 'src/components/CodeEditor/declarations');
const fontsPath = path.resolve(__dirname, 'src/fonts');
const config = async (env: Env): Promise<Configuration> => {
const baseConfig = await grafanaConfig(env);
if (baseConfig.module?.rules) {
if (!Array.isArray(baseConfig.module.rules)) {
throw new Error('Expected baseConfig.module.rules to be an array');
}
if (baseConfig.module.rules.length < 2) {
throw new Error('baseConfig.module.rules is missing rules');
}
const javascriptParserRule = baseConfig.module.rules[1];
if (javascriptParserRule == null || typeof javascriptParserRule !== 'object') {
throw new Error('Expected baseConfig.module.rules[1] to be an object (RuleSetRule)');
}
javascriptParserRule.exclude = [/node_modules/, htmlGraphicsDeclarationsPath];
} else {
throw new Error('Expected baseConfig.module.rules to be defined');
}
return merge(baseConfig, {
module: {
rules: [
{
test: /\.d\.ts?$/,
type: 'asset/resource',
resource: [htmlGraphicsDeclarationsPath],
generator: {
filename: 'declarations/[hash].d.ts',
},
},
{
test: /\.txt$/,
type: 'asset/resource',
resource: [fontsPath],
generator: {
filename: 'fonts/[name]+[hash][ext]',
},
},
{
test: /\.(woff|woff2|eot|ttf|otf)(\?v=\d+\.\d+\.\d+)?$/,
type: 'asset/resource',
resource: [fontsPath],
generator: {
filename: 'fonts/[name]+[hash][ext]',
},
},
],
},
});
};
export default config;