forked from cypress-io/cypress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.ts
126 lines (112 loc) · 2.86 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
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
115
116
117
118
119
120
121
122
123
124
125
126
import _ from 'lodash'
import { getCommonConfig, getSimpleConfig, getCopyWebpackPlugin } from '@packages/web-config/webpack.config.base'
import * as cyIcons from '@packages/icons'
import path from 'path'
import webpack from 'webpack'
const commonConfig = getCommonConfig()
const CopyWebpackPlugin = getCopyWebpackPlugin()
// @ts-ignore
const babelLoader = _.find(commonConfig.module.rules, (rule) => {
// @ts-ignore
return _.includes(rule.use.loader, 'babel-loader')
})
// @ts-ignore
babelLoader.use.options.plugins.push([require.resolve('babel-plugin-prismjs'), {
'languages': ['javascript', 'coffeescript', 'typescript', 'jsx', 'tsx'],
'plugins': ['line-numbers', 'line-highlight'],
'theme': 'default',
'css': false,
}])
let pngRule
// @ts-ignore
const nonPngRules = _.filter(commonConfig.module.rules, (rule) => {
// @ts-ignore
if (rule.test.toString().includes('png')) {
pngRule = rule
return false
}
return true
})
pngRule.use[0].options = {
name: '[name].[ext]',
outputPath: 'img',
publicPath: '/__cypress/runner/img/',
}
// @ts-ignore
const mainConfig: webpack.Configuration = {
...commonConfig,
module: {
rules: [
...nonPngRules,
pngRule,
],
},
entry: {
cypress_runner: [path.resolve(__dirname, 'src/index.js')],
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js',
},
}
// @ts-ignore
mainConfig.plugins = [
// @ts-ignore
...mainConfig.plugins,
new CopyWebpackPlugin([{
// @ts-ignore // There's a race condition in how these types are generated.
from: cyIcons.getPathToFavicon('favicon.ico'),
}]),
]
mainConfig.resolve = {
...mainConfig.resolve,
alias: {
'bluebird': require.resolve('bluebird'),
'lodash': require.resolve('lodash'),
'mobx': require.resolve('mobx'),
'mobx-react': require.resolve('mobx-react'),
'react': require.resolve('react'),
'react-dom': require.resolve('react-dom'),
},
}
// @ts-ignore
const crossOriginConfig: webpack.Configuration = {
...commonConfig,
entry: {
cypress_cross_origin_runner: [path.resolve(__dirname, 'src/cross-origin.js')],
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js',
},
}
// @ts-ignore
const mainInjectionConfig: webpack.Configuration = {
...getSimpleConfig(),
mode: 'production',
entry: {
injection: [path.resolve(__dirname, 'injection/main.js')],
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js',
},
}
// @ts-ignore
const crossOriginInjectionConfig: webpack.Configuration = {
...getSimpleConfig(),
mode: 'production',
entry: {
injection_cross_origin: [path.resolve(__dirname, 'injection/cross-origin.js')],
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js',
},
}
export default [
mainConfig,
mainInjectionConfig,
crossOriginConfig,
crossOriginInjectionConfig,
]