Skip to content

Commit 435015f

Browse files
authored
refactor: simplify web target check by using compiler.platform.web (#118)
1 parent 458997b commit 435015f

1 file changed

Lines changed: 1 addition & 37 deletions

File tree

src/server.ts

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -391,45 +391,9 @@ class Server<
391391
return path.resolve(dir, 'node_modules/.cache/rspack-dev-server');
392392
}
393393

394-
static isWebTarget(compiler: Compiler): boolean {
395-
if (compiler.platform?.web) {
396-
return compiler.platform.web;
397-
}
398-
399-
// TODO improve for the next major version and keep only `webTargets` to fallback for old versions
400-
if (compiler.options.externalsPresets?.web) {
401-
return true;
402-
}
403-
404-
if (compiler.options.resolve?.conditionNames?.includes('browser')) {
405-
return true;
406-
}
407-
408-
const webTargets: (string | undefined | null)[] = [
409-
'web',
410-
'webworker',
411-
'electron-preload',
412-
'electron-renderer',
413-
'nwjs',
414-
'node-webkit',
415-
undefined,
416-
null,
417-
];
418-
419-
if (Array.isArray(compiler.options.target)) {
420-
return compiler.options.target.some((r: string | undefined | null) =>
421-
webTargets.includes(r),
422-
);
423-
}
424-
425-
return webTargets.includes(
426-
compiler.options.target as string | undefined | null,
427-
);
428-
}
429-
430394
addAdditionalEntries(compiler: Compiler) {
431395
const additionalEntries: string[] = [];
432-
const isWebTarget = Server.isWebTarget(compiler);
396+
const isWebTarget = Boolean(compiler.platform.web);
433397

434398
// TODO maybe empty client
435399
if (this.options.client && isWebTarget) {

0 commit comments

Comments
 (0)