Skip to content

Commit 8e894a0

Browse files
authored
fix(webpack-dev-server): remove output.publicPath from webpack-dev-server (#15839)
* fix: remove publicPath in react-scripts if it is present * fix: remove publicPath in react-scripts if it is present * fix: remove publicPath in webpack-dev-server regardless * fix: add root path * chore: revert * fix: remove user base path * remove unused function * test: add unit test for make webpack config * chore: make purpose for fake url more clear * do not include local filesystem path in snapshot
1 parent 726120d commit 8e894a0

File tree

5 files changed

+51
-5
lines changed

5 files changed

+51
-5
lines changed

npm/react/examples/react-scripts/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"react-dom": "17.0.1",
1818
"react-scripts": "4.0.2"
1919
},
20+
"homepage": "/fake-to-avoid-regression-https://github.com/cypress-io/cypress/issues/15811",
2021
"browserslist": {
2122
"production": [
2223
">0.2%",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
exports['makeWebpackConfig ignores userland webpack `output.publicPath` 1'] = {
2+
"output": {
3+
"publicPath": "/test-public-path/",
4+
"filename": "[name].js"
5+
},
6+
"mode": "development",
7+
"optimization": {
8+
"splitChunks": {
9+
"chunks": "all"
10+
}
11+
},
12+
"plugins": [
13+
"HtmlWebpackPlugin",
14+
"CypressCTOptionsPlugin",
15+
"LazyCompilePlugin"
16+
]
17+
}

npm/webpack-dev-server/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"@types/webpack-dev-server": "^3.11.1",
2121
"chai": "^4.2.0",
2222
"mocha": "^8.1.3",
23+
"snap-shot-it": "7.9.3",
2324
"speed-measure-webpack-plugin": "1.4.2",
2425
"typescript": "^4.2.3",
2526
"webpack": "^4.44.2",

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

+1-5
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ interface MakeWebpackConfigOptions extends CypressCTOptionsPluginOptions, UserWe
2323
isOpenMode: boolean
2424
}
2525

26-
const mergePublicPath = (baseValue = '/', userValue = '/') => {
27-
return path.join(baseValue, userValue, '/')
28-
}
29-
3026
function getLazyCompilationWebpackConfig (options: MakeWebpackConfigOptions): webpack.Configuration {
3127
if (options.disableLazyCompilation || !options.isOpenMode) {
3228
return {}
@@ -53,7 +49,7 @@ export async function makeWebpackConfig (userWebpackConfig: webpack.Configuratio
5349

5450
const entry = path.resolve(__dirname, './browser.js')
5551

56-
const publicPath = mergePublicPath(devServerPublicPathRoute, userWebpackConfig?.output?.publicPath)
52+
const publicPath = path.join(devServerPublicPathRoute, '/')
5753

5854
const dynamicWebpackConfig = {
5955
output: {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { expect } from 'chai'
2+
import snapshot from 'snap-shot-it'
3+
import { makeWebpackConfig } from '../../src/makeWebpackConfig'
4+
5+
describe('makeWebpackConfig', () => {
6+
it('ignores userland webpack `output.publicPath`', async () => {
7+
const actual = await makeWebpackConfig({
8+
output: {
9+
publicPath: '/this-will-be-ignored',
10+
},
11+
}, {
12+
devServerPublicPathRoute: '/test-public-path',
13+
isOpenMode: true,
14+
supportFile: '/support.js',
15+
projectRoot: '.',
16+
files: [],
17+
})
18+
19+
// plugins contain circular deps which cannot be serialized in a snapshot.
20+
// instead just compare the name and order of the plugins.
21+
// @ts-expect-error
22+
actual.plugins = actual.plugins.map((p) => p.constructor.name)
23+
24+
// these will include paths from the user's local file system, so we should not include them the snapshot
25+
delete actual.output.path
26+
delete actual.entry
27+
28+
expect(actual.output.publicPath).to.eq('/test-public-path/')
29+
snapshot(actual)
30+
})
31+
})

0 commit comments

Comments
 (0)