NX Plugin for generating opinionated Vue3+Vite+PostCSS applications
- 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
=><root>/src/app
@assets
=><root>/src/assets
@public
=><root>/src/public
⚠️ These project-local path aliases may be removed once this issue is resolved: #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
npm install nx-vue3-vite --save-dev
nx g nx-vue3-vite:app <app-name>
nx serve <app-name>
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 <app-name> [options]
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 <name> [options]
# Alias
nx g nx-vue3-vite:c <name> [options]
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 |
nx g nx-vue3-vite:library <lib-name> [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 |
nx g nx-vue3-vite:docs <app-name> [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 |
Generate a Cypress e2e app targeting an application generated with nx-vue3-vite:app
nx g nx-vue3-vite:cypress <app-name> --project <target-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 <project>-e2e |
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 |
(NX Docs)
Development server executor for generated Vue3 projects.
nx serve <app-name> [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 |
Development server executor for generated Vitepress docs projects.
nx serve <app-name> [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 |
Preview server executor for generated Vue3 projects.
nx preview <app-name> [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 |
Build executor for generated Vue3 projects and libraries
nx build <app-name> [options]
Arguments | Description |
---|---|
app-name | The name of your app |
Options | Default | Description |
---|---|---|
--dist | localhost | Output directory |
Build executor for generated Vitepress docs.
nx build <app-name> [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 |
nx lint <app-name> [options]
See options for @nx/eslint
Note: see vite-jest section for progress on testing code that relies on Vite transforms.
nx test <app-name> [options]
See options for @nx/jest
Generator TBD
nx e2e <app-name> [options]
See options for @nx/cypress
Documentation for non-ideal setup that should be removed or replaced when possible.
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
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.