<h2 align='center'>nx-vue3-vite</h2>
npm install nx-vue3-viteNX Plugin for generating opinionated Vue3+Vite+PostCSS applications
- Overview
- Plugin Usage
- Install
- Generate App
- Serve
- Vue3 Generators
- Application
- Component
- Library
- Vitepress Docs
- Cypress
- Vue3 Executors
- Dev Server
- Docs Dev Server
- Preview Server
- Build
- Docs Build
- Lint
- Unit Testing
- Cypress E2E
- Workarounds
- dep-graph hack
- vue3-jest
- vite-jest
- Vue3+Vite+Postcss project generation
- Vue3+Vite+Postcss library generation
- Component generation for projects/libraries
- Vitepress docs project generation
The intent of this plugin is to help generate a Vue3 related projects and components for Nx. The recommended configuration and folder structures are used where possible in order to integrate smoothly. Some path aliases are provided for convenience:
- @app =>
- @assets =>
- @public =>
> :warning: These project-local path aliases may be removed once this issue is resolved: https://github.com/samatechtw/nx-vue3-vite/issues/35
One compromise made is keeping index.html in the root folder. Vite strongly suggests this, since it treats index.html as the entry point and requires some configuration to change it.
The following steps assume you are working within an existing Nx workspace. To create one, run npx create-nx-workspace@latest (docs)
npm
``bash`
npm install nx-vue3-vite --save-dev
`bash`
nx g nx-vue3-vite:app
`bash`
nx serve
This plugin adds a few recommended extensions to VSCode. To install them, open VSCode and:
- Open the command palette [CMD] + [Shift] + [p] and type "Show Recommended Extensions"
- Review and install extensions under "WORKSPACE RECOMMENDATIONS"
(NX Docs)
``
nx g nx-vue3-vite:app
| Arguments | Description |
| --------- | ----------------------------- |
| app-name | The name of the generated app |
| Options | Default | Description |
| ----------- | ------- | ---------------------------------------------------------------------------------------- |
| --title | - | Project title, defaults to
| --tags | - | Comma delimited tags for linting |
| --directory | apps | Workspace directory to place the Vue project |
| --alias | global | Whether to use local (project tsconfig) or global (root tsconfig.base.json) path aliases |
| --test | vitest | The testing framework of the project |
`
nx g nx-vue3-vite:component
| Arguments | Description |
| --------- | -------------------------- |
| name | The name of the component. |
| Options | Default | Description |
| ----------- | ---------------------------------------------------------- | -------------------------------------------------------------------------------------------- |
| --project | - | The name of the project. |
| --directory |
app/components for applications, and lib for libraries | Directory relative to src where the component will be generated |
| --lang | ts | Script language: ['ts', 'js'] |
| --setup | true | Script setup syntax sugar |
| --style | postcss | CSS Preprocessor: ['css', 'scss', 'less', 'stylus', 'postcss'] |
| --scoped | false | Whether the component's style block is scoped |$3
`
nx g nx-vue3-vite:library [options]
`| Arguments | Description |
| --------- | --------------------------------- |
| lib-name | The name of the generated library |
| Options | Default | Description |
| ----------- | ------- | -------------------------------------------- |
| --tags | - | Comma delimited tags for linting |
| --directory | - | Workspace directory to place the Vue library |
| --test | vitest | The testing framework of the project |
$3
`
nx g nx-vue3-vite:docs [options]
`| Arguments | Description |
| --------- | ---------------------------------- |
| app-name | The name of the generated docs app |
| Options | Default | Description |
| ----------- | ------- | ----------------------------------------------- |
| --title | - | Docs title, defaults to |
| --tags | - | Comma delimited tags for linting |
| --directory | apps | Workspace directory to place the Vitepress docs |
$3
Generate a Cypress e2e app targeting an application generated with
nx-vue3-vite:app`
nx g nx-vue3-vite:cypress --project [options]
`| Arguments | Description |
| --------- | -------------------------------------------------------------------------------------------------------------------------- |
| app-name | Optional name for the e2e app. You can provide the
project option instead, which results in an app named |Many Cypress options are available, which you can check here
| Options | Default | Description |
| ------------- | ------- | -------------------------------------------------------------------------------------------- |
| --project | - | Existing project name to generate e2e testing for |
| --tags | - | Comma delimited tags for linting |
| --directory | apps | Workspace directory to place the app |
| headlessWatch | false | Only valid in headless mode. If true, Cypress will watch for code changes instead of exiting |
| headlessCI | true | If env var CI=true, set
headless=true and headlessWatch=false |Vue3 Executors
(NX Docs)
$3
Development server executor for generated Vue3 projects.
`
nx serve [options]
`| Arguments | Description |
| --------- | -------------------- |
| app-name | The name of your app |
| Options | Default | Description |
| ------- | --------- | ---------------------------------------------------------------- |
| --host | localhost | Server host location |
| --port | 3000 | Server port |
| --https | false | Run in HTTPS/SSL mode |
$3
Development server executor for generated Vitepress docs projects.
`
nx serve [options]
`| Arguments | Description |
| --------- | ----------------------------- |
| app-name | The name of the Vitepress app |
| Options | Default | Description |
| ------- | --------- | ---------------------------------------------------------------- |
| --root | docs | Vitepress docs root, relative to the app root |
| --host | localhost | Server host location |
| --port | 3000 | Server port |
| --https | false | Run in HTTPS/SSL mode |
$3
Preview server executor for generated Vue3 projects.
`
nx preview [options]
`| Arguments | Description |
| --------- | -------------------- |
| app-name | The name of your app |
| Options | Default | Description |
| ------- | --------- | -------------------------------------------------------------------------------- |
| --dist | | The build output directory to preview |
| --host | localhost | Preview Server host location |
| --port | 3000 | Preview Server port |
| --https | false | Run in HTTPS/SSL mode |
$3
Build executor for generated Vue3 projects and libraries
`
nx build [options]
`| Arguments | Description |
| --------- | -------------------- |
| app-name | The name of your app |
| Options | Default | Description |
| ------- | --------- | ----------------------------------------------------------- |
| --dist | localhost | Output directory |
$3
Build executor for generated Vitepress docs.
`
nx build [options]
`| Arguments | Description |
| --------- | ----------------------------- |
| app-name | The name of the Vitepress app |
| Options | Default | Description |
| ------- | --------- | ----------------------------------------------------------- |
| --root | docs | Vitepress docs root, relative to the app root |
| --dist | localhost | Output directory |
$3
`
nx lint [options]
`See options for
@nx/eslint$3
Note: see vite-jest section for progress on testing code that relies on Vite transforms.
`
nx test [options]
`See options for
@nx/jest$3
Generator TBD
`
nx e2e [options]
`See options for
@nx/cypressWorkarounds
Documentation for non-ideal setup that should be removed or replaced when possible.
$3
In order to get
nx dep-graph to work in a generated Vue app, the NX code responsible for parsing file extension must be patched.The
build and serve executors in this plugin automatically check your workspace node_modules to see if the patch is already installed, and installs if not. See packages/vue3-vite/patch-nx-dep-graph.js.Patch details: https://github.com/ZachJW34/nx-plus/tree/master/libs/vue#nx-dependency-graph-support
Related NX issue: https://github.com/nx/nx/issues/2960
$3
Currently, unit tests will throw warnings when mounting Vue components that rely on code transforms from Vite plugins. This is because Jest does not know about Vite, and relies directly on SFC compilation from
vue3-jest`. The [vite-jest] project will eventually solve this problem, or we may implement our own transformer. The main issue now is Vite requires async for dependency resolution and transforming code, but Jest support is rudimentary/alpha.