Files
cypress/packages/runner/webpack.config.ts
T
Bill Glesias f1454dd0d1 chore: upgrade webpack dependencies to latest v4 compatible (#27396)
* chore: upgrade webpack dependencies to latest sub 5 compat [run ci]

* chore: updating v8 snapshot cache

* chore: updating v8 snapshot cache

* chore: updating v8 snapshot cache

* chore: build binaries [run ci]

* chore: update snapshot for darwin

* chore: downgrade tsconfig-paths-webpack-loader from v4 to v3 [run ci]

* [run ci]

* chore: add rimraf in @packages/runner to use in prebuild command to clear out dist directory to get windows compat [run ci]

* don't pass -rf flags into rimraf as it is inherit with the command

---------

Co-authored-by: cypress-bot[bot] <+cypress-bot[bot]@users.noreply.github.com>
2023-07-31 14:19:11 -04:00

134 lines
3.0 KiB
TypeScript

import _ from 'lodash'
import { waitUntilIconsBuilt } from '../../scripts/ensure-icons'
import { getCommonConfig, getSimpleConfig, getCopyWebpackPlugin } from '@packages/web-config/webpack.config.base'
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',
},
}
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 async function () {
await waitUntilIconsBuilt()
const cyIcons = require('@packages/icons')
mainConfig.plugins = [
// @ts-ignore
...mainConfig.plugins,
new CopyWebpackPlugin({
patterns: [{
// @ts-ignore // There's a race condition in how these types are generated.
from: cyIcons.getPathToFavicon('favicon.ico'),
}],
}),
]
return [
mainConfig,
mainInjectionConfig,
crossOriginConfig,
crossOriginInjectionConfig,
]
}