-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
preprocessor.ts
46 lines (43 loc) · 1.12 KB
/
preprocessor.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
import * as wp from '@cypress/webpack-preprocessor';
import { TsconfigPathsPlugin } from 'tsconfig-paths-webpack-plugin';
import * as nodeExternals from 'webpack-node-externals';
export function preprocessTypescript(config: any) {
if (!config.env.tsConfig) {
throw new Error(
'Please provide an absolute path to a tsconfig.json as cypressConfig.env.tsConfig'
);
}
return wp({
webpackOptions: getWebpackConfig(config)
});
}
export function getWebpackConfig(config: any) {
const extensions = ['.ts', '.tsx', '.mjs', '.js', '.jsx'];
return {
resolve: {
extensions,
plugins: [
new TsconfigPathsPlugin({
configFile: config.env.tsConfig,
extensions
})
]
},
module: {
rules: [
{
test: /\.(j|t)sx?$/,
loader: 'ts-loader',
exclude: [/node_modules/],
options: {
configFile: config.env.tsConfig,
// https://github.com/TypeStrong/ts-loader/pull/685
experimentalWatchApi: true
}
}
]
},
plugins: [],
externals: [nodeExternals()]
};
}