-
Notifications
You must be signed in to change notification settings - Fork 8
/
webpack.config.ts
47 lines (41 loc) · 1.52 KB
/
webpack.config.ts
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
import type { Configuration } from 'webpack';
import { merge } from 'webpack-merge';
import grafanaConfig from './.config/webpack/webpack.config';
import pluginJson from './src/plugin.json';
import path from 'path';
const htmlGraphicsDeclarationsPath = path.resolve(__dirname, 'src/components/CodeEditor/declarations');
const config = async (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 === 0) {
throw new Error('baseConfig.module.rules is missing rules');
}
const javascriptParserRule = baseConfig.module.rules[0];
if (javascriptParserRule == null || typeof javascriptParserRule !== 'object') {
throw new Error('Expected baseConfig.module.rules[0] 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: {
publicPath: `public/plugins/${pluginJson.id}/declarations/`,
outputPath: 'declarations/',
filename: '[hash].d.ts',
},
},
],
},
});
};
export default config;