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

thread config in nx-vite build and serve #60

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/silent-masks-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@wanews/nx-vite': minor
---

Provides the ability to thread vite config file to vite (using vite.config.js as a default)
8 changes: 6 additions & 2 deletions libs/nx-vite/src/executors/build/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { build } from 'vite'
import { BuildExecutorSchema } from './schema'

export default async function runExecutor(
_options: BuildExecutorSchema,
options: BuildExecutorSchema,
context: ExecutorContext,
) {
if (!context.projectName) {
Expand All @@ -13,8 +13,12 @@ export default async function runExecutor(
const tree = new FsTree(context.cwd, context.isVerbose)
const appRoot = context.workspace.projects[context.projectName].root

const root = tree.root + '/' + appRoot
const configFile = options.configFile

await build({
root: tree.root + '/' + appRoot,
root,
configFile
})

return {
Expand Down
4 changes: 3 additions & 1 deletion libs/nx-vite/src/executors/build/schema.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface BuildExecutorSchema {}
export interface BuildExecutorSchema {
configFile?: string
}
6 changes: 5 additions & 1 deletion libs/nx-vite/src/executors/build/schema.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"properties": {},
"properties": {
"configFile": {
"type": "string"
}
},
"type": "object",
"cli": "nx",
"title": "Vite Build Executor"
Expand Down
7 changes: 5 additions & 2 deletions libs/nx-vite/src/executors/serve/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import execa from 'execa'
import { ServeExecutorSchema } from './schema'

export default async function runExecutor(
_options: ServeExecutorSchema,
options: ServeExecutorSchema,
context: ExecutorContext,
) {
if (!context.projectName) {
Expand All @@ -15,9 +15,12 @@ export default async function runExecutor(
const tree = new FsTree(context.cwd, context.isVerbose)
const appRoot = context.workspace.projects[context.projectName].root

const root = `${tree.root}/${appRoot}`
const configFile = options.configFile

const vite = execa(
packageManager.exec,
['vite', `${tree.root}/${appRoot}`, '--open'],
['vite', root, ...(configFile ? ['--config', configFile] : []), '--open'],
{
stdio: [process.stdin, process.stdout, 'pipe'],
},
Expand Down
4 changes: 3 additions & 1 deletion libs/nx-vite/src/executors/serve/schema.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface ServeExecutorSchema {}
export interface ServeExecutorSchema {
configFile?: string
}
6 changes: 5 additions & 1 deletion libs/nx-vite/src/executors/serve/schema.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"properties": {},
"properties": {
"configFile": {
"type": "string"
}
},
"type": "object",
"cli": "nx",
"title": "Vite Serve Executor"
Expand Down