Skip to content

Commit 69f7dab

Browse files
authored
fix: revert dynamic import of webpack config file (#24598)
1 parent 5e3a21c commit 69f7dab

File tree

13 files changed

+2233
-8
lines changed

13 files changed

+2233
-8
lines changed

npm/webpack-dev-server/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"fs-extra": "9.1.0",
2222
"html-webpack-plugin-4": "npm:html-webpack-plugin@^4",
2323
"html-webpack-plugin-5": "npm:html-webpack-plugin@^5",
24+
"local-pkg": "0.4.1",
2425
"speed-measure-webpack-plugin": "1.4.2",
2526
"tslib": "^2.3.1",
2627
"webpack-dev-server": "^4.7.4",

npm/webpack-dev-server/src/makeWebpackConfig.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { debug as debugFn } from 'debug'
22
import * as path from 'path'
33
import { merge } from 'webpack-merge'
4+
import { importModule } from 'local-pkg'
45
import type { Configuration, EntryObject } from 'webpack'
56
import { makeCypressWebpackConfig } from './makeDefaultWebpackConfig'
67
import type { CreateFinalWebpackConfig } from './createWebpackDevServer'
78
import { configFiles } from './constants'
8-
import { dynamicAbsoluteImport, dynamicImport } from './dynamic-import'
9+
import { dynamicImport } from './dynamic-import'
910

1011
const debug = debugFn('cypress:webpack-dev-server:makeWebpackConfig')
1112

@@ -90,7 +91,7 @@ export async function makeWebpackConfig (
9091

9192
if (configFile) {
9293
debug('found webpack config %s', configFile)
93-
const sourcedConfig = await dynamicAbsoluteImport(configFile)
94+
const sourcedConfig = await importModule(configFile)
9495

9596
debug('config contains %o', sourcedConfig)
9697
if (sourcedConfig && typeof sourcedConfig === 'object') {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { defineConfig } from 'cypress'
2+
3+
export default defineConfig({
4+
component: {
5+
devServer: {
6+
bundler: 'webpack',
7+
} as any,
8+
supportFile: false,
9+
},
10+
})
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width,initial-scale=1.0">
7+
<title>Components App</title>
8+
</head>
9+
<body>
10+
<div data-cy-root></div>
11+
</body>
12+
</html>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const helloWorld = () => {
2+
return 'Hello World'
3+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "ct-webpack-ts",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"dependencies": {
10+
"html-webpack-plugin": "^5.5.0",
11+
"ts-loader": "^9.4.1",
12+
"typescript": "^4.8.4",
13+
"webpack": "^5.74.0",
14+
"webpack-dev-server": "^4.11.1"
15+
},
16+
"license": "ISC",
17+
"author": "",
18+
"keywords": []
19+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { helloWorld } from './helloWorld'
2+
3+
it('should return "Hello World"', () => {
4+
expect(helloWorld()).eq('Hello World')
5+
})
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"compilerOptions": {
3+
"module": "esnext",
4+
"moduleResolution": "node"
5+
},
6+
"include": ["**/*.ts"]
7+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export default {
2+
mode: 'development',
3+
devtool: 'inline-source-map',
4+
entry: './app.ts',
5+
output: {
6+
filename: 'bundle.js',
7+
},
8+
resolve: {
9+
// Add `.ts` and `.tsx` as a resolvable extension.
10+
extensions: ['.ts', '.tsx', '.js'],
11+
// Add support for TypeScripts fully qualified ESM imports.
12+
extensionAlias: {
13+
'.js': ['.js', '.ts'],
14+
'.cjs': ['.cjs', '.cts'],
15+
'.mjs': ['.mjs', '.mts'],
16+
},
17+
},
18+
module: {
19+
rules: [
20+
// all files with a `.ts`, `.cts`, `.mts` or `.tsx` extension will be handled by `ts-loader`
21+
{ test: /\.([cm]?ts|tsx)$/, loader: 'ts-loader' },
22+
],
23+
},
24+
}

0 commit comments

Comments
 (0)