Skip to content

Commit c25bb3a

Browse files
mandarinivsavkin
authored andcommitted
fix(vite): delete webpack config when converting (#14582)
1 parent ba3c8c8 commit c25bb3a

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

packages/vite/src/generators/configuration/configuration.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
UserProvidedTargetName,
1919
TargetFlags,
2020
addPreviewTarget,
21+
deleteWebpackConfig,
2122
} from '../../utils/generator-utils';
2223

2324
import initGenerator from '../init/init';
@@ -27,7 +28,7 @@ import { Schema } from './schema';
2728
export async function viteConfigurationGenerator(tree: Tree, schema: Schema) {
2829
const tasks: GeneratorCallback[] = [];
2930

30-
const { targets, projectType } = readProjectConfiguration(
31+
const { targets, projectType, root } = readProjectConfiguration(
3132
tree,
3233
schema.project
3334
);
@@ -134,6 +135,13 @@ export async function viteConfigurationGenerator(tree: Tree, schema: Schema) {
134135
if (projectType === 'application') {
135136
moveAndEditIndexHtml(tree, schema, buildTargetName);
136137
}
138+
139+
deleteWebpackConfig(
140+
tree,
141+
root,
142+
targets[buildTargetName]?.options?.webpackConfig
143+
);
144+
137145
editTsConfig(tree, schema);
138146
}
139147

packages/vite/src/utils/generator-utils.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,24 @@ export function editTsConfig(tree: Tree, options: Schema) {
362362
writeJson(tree, `${projectConfig.root}/tsconfig.json`, config);
363363
}
364364

365+
export function deleteWebpackConfig(
366+
tree: Tree,
367+
projectRoot: string,
368+
webpackConfigFilePath?: string
369+
) {
370+
const webpackConfigPath =
371+
webpackConfigFilePath && tree.exists(webpackConfigFilePath)
372+
? webpackConfigFilePath
373+
: tree.exists(`${projectRoot}/webpack.config.js`)
374+
? `${projectRoot}/webpack.config.js`
375+
: tree.exists(`${projectRoot}/webpack.config.ts`)
376+
? `${projectRoot}/webpack.config.ts`
377+
: null;
378+
if (webpackConfigPath) {
379+
tree.delete(webpackConfigPath);
380+
}
381+
}
382+
365383
export function moveAndEditIndexHtml(
366384
tree: Tree,
367385
options: Schema,

0 commit comments

Comments
 (0)