-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathrsbuild.config.ts
More file actions
114 lines (111 loc) · 2.82 KB
/
Copy pathrsbuild.config.ts
File metadata and controls
114 lines (111 loc) · 2.82 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import fs from 'node:fs';
import path from 'node:path';
import { defineConfig } from '@rsbuild/core';
import { pluginLess } from '@rsbuild/plugin-less';
import { pluginNodePolyfill } from '@rsbuild/plugin-node-polyfill';
import { pluginReact } from '@rsbuild/plugin-react';
import { pluginSvgr } from '@rsbuild/plugin-svgr';
import { pluginWorkspaceDev } from 'rsbuild-plugin-workspace-dev';
import {
commonIgnoreWarnings,
createReportTemplateSyncPlugin,
createTypeCheckPlugin,
} from '../../scripts/rsbuild-utils.ts';
// Read all JSON files from test-data directory
const testDataDir = path.join(__dirname, 'test-data');
const jsonFiles = fs
.readdirSync(testDataDir)
.filter((file) => file.endsWith('.json'));
const allTestData = jsonFiles.map((file) => {
const filePath = path.join(testDataDir, file);
const data = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
return {
fileName: file,
data,
};
});
const reportTemplatePath = path.join(__dirname, 'dist', 'index.html');
const coreReportTemplatePath = path.join(
__dirname,
'..',
'..',
'packages',
'core',
'dist',
'report-template',
'index.html',
);
export default defineConfig({
html: {
template: './template/index.html',
inject: 'body',
tags:
process.env.NODE_ENV === 'development'
? allTestData.map((item, index) => ({
tag: 'script',
attrs: {
type: 'midscene_web_dump',
playwright_test_description: item.data.groupDescription,
playwright_test_id: `id-${index}`,
playwright_test_title: item.data.groupName,
playwright_test_status: 'passed',
playwright_test_duration: Math.round(
Math.random() * 100000,
).toString(),
},
children: JSON.stringify(item.data),
}))
: [],
},
source: {
tsconfigPath: 'tsconfig.build.json',
},
resolve: {
alias: {
async_hooks: path.join(
__dirname,
'../../packages/shared/src/polyfills/async-hooks.ts',
),
},
},
dev: {
writeToDisk: true,
},
tools: {
rspack: {
module: {
parser: {
javascript: {
dynamicImportMode: 'eager',
},
},
},
externals: ['sharp'],
ignoreWarnings: commonIgnoreWarnings,
},
},
output: {
assetPrefix: './',
inlineScripts: true,
injectStyles: true,
},
plugins: [
pluginReact(),
pluginLess(),
pluginNodePolyfill(),
pluginSvgr(),
createTypeCheckPlugin(),
createReportTemplateSyncPlugin({
srcPath: reportTemplatePath,
destPath: coreReportTemplatePath,
pluginName: 'sync-report-template-to-core',
}),
pluginWorkspaceDev({
projects: {
'@midscene/report': {
skip: true,
},
},
}),
],
});