-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathts-preprocessor.ts
58 lines (50 loc) · 1.34 KB
/
ts-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
47
48
49
50
51
52
53
54
55
56
57
58
import { TsconfigPathsPlugin } from 'tsconfig-paths-webpack-plugin';
import path from 'path';
import type { Configuration } from 'webpack';
export const preprocessor = (isCoverage: boolean) => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const tsconfigPath = path.resolve(__dirname, '../tsconfig.json');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const wp = require('@cypress/webpack-preprocessor');
const coverageRule = {
test: /\.ts$/,
exclude: [/node_modules/],
loader: '@ephesoft/webpack.istanbul.loader', // Must be first loader
};
const tsRule = {
test: /\.ts$/,
exclude: [/node_modules/],
use: [
{
loader: 'ts-loader',
options: {
transpileOnly: true,
},
},
],
};
const rules = isCoverage ? [coverageRule, tsRule] : [tsRule];
const webpackOptions: Configuration = {
resolve: {
extensions: ['.ts', '.js', '.json'],
plugins: [
// to resolve paths from tsconfig (i.e.cy-local)
new TsconfigPathsPlugin({
configFile: tsconfigPath,
silent: true,
}),
],
},
module: {
rules,
},
cache: false,
stats: 'verbose',
mode: 'development',
devtool: 'source-map',
};
const options = {
webpackOptions,
};
return wp(options);
};