Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(vite): nodes for build, serve, test, preview targets #20086

Merged
merged 2 commits into from Nov 30, 2023

Conversation

mandarini
Copy link
Member

@mandarini mandarini commented Nov 7, 2023

A plugin (@nx/vite/plugin) which will add Vite targets/projects to the Nx project graph. This allows you to run Vite for projects that have a vite.config.ts file without creating a project.json file.

To-do's

  • Read outputs from vite.config.ts
  • Figure out why it does not like .js
  • Figure out cannot use import outside module on pure .ts vite apps
  • Vitest: passWithNoTests should be moved to targetDefaults like jest
  • Vitest: reportsDirectory shouldn't be passed in the executor options but rather in the config
  • node for static-serve

Once this PR is merged, we can add the cypress web server config.

How it works

On @nx/vite:init (which is called through the @nx/vite:configuration generator, and the @nx/react:app|lib and @nx/web:app|lib generators) this is added in the nx.json:

...
plugins: [
  {
    plugin: '@nx/vite/plugin',
    options: {
      buildTargetName: 'build',
      previewTargetName: 'preview',
      testTargetName: 'test',
      serveTargetName: 'serve',
    },
  },
  ...
]

so that you can run nx build vite, nx test vite etc, without manually defining these targets in your projects' project.json.

The plugin generates these targets with bare minimum (no extra) options configuration. Any options you need for your vite app, you can add in your project's vite.config.ts.

Docs changes

Simple docs page: https://nx-dev-git-fork-mandarini-feat-vite-nodes-nrwl.vercel.app/nx-api/vite/documents/vite-nodes-plugin (to be discussed?)

FIXED ISSUES

FIXED: Why it does not like js

 >  NX   require() of ES Module /Users/fileas/Projects/nrwl/test-nx-workspaces/vitenodes/rlibjs/vite.config.js from /Users/fileas/Projects/nrwl/test-nx-workspaces/vitenodes/node_modules/@nx/vite/src/plugins/plugin.js not supported.

   Instead change the require of vite.config.js in /Users/fileas/Projects/nrwl/test-nx-workspaces/vitenodes/node_modules/@nx/vite/src/plugins/plugin.js to a dynamic import() which is available in all CommonJS modules.

Solutions

  1. This can be solved once the createNodes function handles async.
  2. This can be solved now using readFileSync and then AST parsing.

FIXED: cannot use import outside module on pure .ts vite apps

It does not like the loaded vite.config.ts.

Solutions

  1. This will be solved once we use loadConfigFromFile function, when async is ready
  2. This can be solved now using readFileSync and then AST parsing.

Copy link

vercel bot commented Nov 7, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
nx-dev ✅ Ready (Inspect) Visit Preview Nov 30, 2023 6:57pm

@mandarini mandarini self-assigned this Nov 7, 2023
@mandarini mandarini force-pushed the feat/vite-nodes branch 2 times, most recently from 5f72ba9 to e3b29d8 Compare November 7, 2023 13:31
@mandarini mandarini changed the title feat(vite): add nodes - init commit feat(vite): nodes for build, serve, test, preview targets Nov 8, 2023
@mandarini mandarini force-pushed the feat/vite-nodes branch 2 times, most recently from 7deda84 to 303393d Compare November 8, 2023 15:32
@mandarini mandarini force-pushed the feat/vite-nodes branch 2 times, most recently from fbe0e61 to ccf2dfe Compare November 8, 2023 16:57
@mandarini mandarini marked this pull request as ready for review November 8, 2023 16:58
@mandarini mandarini requested review from a team, jaysoo and Coly010 as code owners November 8, 2023 16:58
@mandarini mandarini requested review from meeroslav and FrozenPandaz and removed request for meeroslav November 8, 2023 16:58
@mandarini mandarini force-pushed the feat/vite-nodes branch 2 times, most recently from f76740b to b512512 Compare November 8, 2023 17:49
@mandarini mandarini requested a review from a team as a code owner November 8, 2023 17:49
@mandarini mandarini force-pushed the feat/vite-nodes branch 2 times, most recently from ab77acc to 49ee5ae Compare November 8, 2023 18:02
@mandarini mandarini enabled auto-merge (squash) November 30, 2023 20:51
@mandarini mandarini merged commit 83db767 into nrwl:master Nov 30, 2023
6 checks passed
Copy link

github-actions bot commented Dec 6, 2023

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants