Skip to content

Commit

Permalink
fix(vite): add prop to config to ensure output dir is emptied #23382 (#…
Browse files Browse the repository at this point in the history
…23466)

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

## Current Behavior
<!-- This is the behavior we have today -->
We do not generate `emptyOutDir` when creating vite config, which throws
a warning and does not delete the output directory when it is outside
the project root.
This is common in integrated workspaces


## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->
`emptyOutDir` should be added to the config

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #23382
  • Loading branch information
Coly010 authored May 17, 2024
1 parent 3bbc964 commit 9451046
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ nxViteTsPaths()],
build: {
outDir: '../dist/my-vite-app',
emptyOutDir: true,
reportCompressedSize: true,
commonjsOptions: {
transformMixedEsModules: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ nxViteTsPaths()],
build: {
outDir: '../dist/my-app',
emptyOutDir: true,
reportCompressedSize: true,
commonjsOptions: {
transformMixedEsModules: true,
Expand Down Expand Up @@ -197,6 +198,7 @@ nxViteTsPaths()],
build: {
outDir: '../dist/my-app',
emptyOutDir: true,
reportCompressedSize: true,
commonjsOptions: {
transformMixedEsModules: true,
Expand Down Expand Up @@ -322,6 +324,7 @@ nxViteTsPaths()],
build: {
outDir: '../dist/my-app',
emptyOutDir: true,
reportCompressedSize: true,
commonjsOptions: {
transformMixedEsModules: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ dts({ entryRoot: 'src', tsconfigPath: path.join(__dirname, 'tsconfig.lib.json')
// See: https://vitejs.dev/guide/build.html#library-mode
build: {
outDir: '../dist/my-lib',
emptyOutDir: true,
reportCompressedSize: true,
commonjsOptions: {
transformMixedEsModules: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default defineConfig({
// See: https://vitejs.dev/guide/build.html#library-mode
build: {
outDir: '../../dist/libs/react-lib-nonb-jest',
emptyOutDir: true,
reportCompressedSize: true,
commonjsOptions: {
transformMixedEsModules: true,
Expand Down Expand Up @@ -82,6 +83,7 @@ export default defineConfig({
// See: https://vitejs.dev/guide/build.html#library-mode
build: {
outDir: '../../dist/libs/react-lib-nonb-jest',
emptyOutDir: true,
reportCompressedSize: true,
commonjsOptions: {
transformMixedEsModules: true,
Expand Down Expand Up @@ -132,6 +134,7 @@ export default defineConfig({
cacheDir: '../../node_modules/.vite/libs/react-lib-nonb-vitest',
build: {
outDir: '../../dist/libs/react-lib-nonb-vitest',
emptyOutDir: true,
reportCompressedSize: true,
commonjsOptions: {
transformMixedEsModules: true,
Expand Down Expand Up @@ -203,6 +206,7 @@ export default defineConfig({
build: {
outDir: '../../dist/apps/my-test-react-app',
emptyOutDir: true,
reportCompressedSize: true,
commonjsOptions: {
transformMixedEsModules: true,
Expand Down Expand Up @@ -260,6 +264,7 @@ export default defineConfig({
build: {
outDir: '../../dist/apps/my-test-web-app',
emptyOutDir: true,
reportCompressedSize: true,
commonjsOptions: {
transformMixedEsModules: true,
Expand Down Expand Up @@ -317,6 +322,7 @@ export default defineConfig({
build: {
outDir: '../../dist/apps/my-test-react-app',
emptyOutDir: true,
reportCompressedSize: true,
commonjsOptions: {
transformMixedEsModules: true,
Expand Down
2 changes: 2 additions & 0 deletions packages/vite/src/utils/generator-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ export function createOrEditViteConfig(
// See: https://vitejs.dev/guide/build.html#library-mode
build: {
outDir: '${buildOutDir}',
emptyOutDir: true,
reportCompressedSize: true,
commonjsOptions: {
transformMixedEsModules: true,
Expand All @@ -395,6 +396,7 @@ export function createOrEditViteConfig(
: `
build: {
outDir: '${buildOutDir}',
emptyOutDir: true,
reportCompressedSize: true,
commonjsOptions: {
transformMixedEsModules: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export default defineConfig({
build: {
outDir: '../dist/test',
emptyOutDir: true,
reportCompressedSize: true,
commonjsOptions: {
transformMixedEsModules: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default defineConfig({
// See: https://vitejs.dev/guide/build.html#library-mode
build: {
outDir: '../dist/my-lib',
emptyOutDir: true,
reportCompressedSize: true,
commonjsOptions: {
transformMixedEsModules: true,
Expand Down Expand Up @@ -125,6 +126,7 @@ export default defineConfig({
// See: https://vitejs.dev/guide/build.html#library-mode
build: {
outDir: '../dist/my-lib',
emptyOutDir: true,
reportCompressedSize: true,
commonjsOptions: {
transformMixedEsModules: true,
Expand Down

0 comments on commit 9451046

Please sign in to comment.