-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(vite): future-proof Vite plugin to support ESM-only version of V…
…ite (#19533)
- Loading branch information
Showing
8 changed files
with
71 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { | ||
checkFilesExist, | ||
newProject, | ||
renameFile, | ||
runCLI, | ||
uniq, | ||
updateJson, | ||
} from '@nx/e2e/utils'; | ||
|
||
// TODO(jack): This test file can be removed when Vite goes ESM-only. | ||
// This test ensures that when CJS is gone from the published `vite` package, Nx will continue to work. | ||
|
||
describe('Vite ESM tests', () => { | ||
beforeAll(() => newProject({ unsetProjectNameAndRootFormat: false })); | ||
|
||
it('should build with Vite when it is ESM-only', async () => { | ||
const appName = uniq('viteapp'); | ||
runCLI(`generate @nx/react:app ${appName} --bundler=vite`); | ||
|
||
// .mts file is needed because Nx will transpile .ts files as CJS | ||
renameFile(`${appName}/vite.config.ts`, `${appName}/vite.config.mts`); | ||
|
||
// Remove CJS entry point for Vite | ||
updateJson('node_modules/vite/package.json', (json) => { | ||
for (const [key, value] of Object.entries(json.exports['.'])) { | ||
if (typeof value === 'string' && value.endsWith('.cjs')) { | ||
delete json.exports['.'][key]; | ||
} | ||
} | ||
return json; | ||
}); | ||
|
||
runCLI(`build ${appName}`); | ||
|
||
checkFilesExist(`dist/${appName}/index.html`); | ||
}); | ||
}); |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1899a9e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
nx-dev – ./
nx-dev-git-master-nrwl.vercel.app
nx-dev-nrwl.vercel.app
nx.dev
nx-five.vercel.app