From 9acc468220a79048445f2ea29e8cf29bf9e19b70 Mon Sep 17 00:00:00 2001 From: jlenon7 Date: Sat, 28 Dec 2024 14:28:52 -0300 Subject: [PATCH] feat(command): improve integration with vite --- package-lock.json | 4 ++-- package.json | 2 +- src/commands/BuildCommand.ts | 24 +++++++++++------------- src/commands/ServeCommand.ts | 19 +++++-------------- 4 files changed, 19 insertions(+), 30 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9aacb5c..57661ce 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@athenna/core", - "version": "5.4.0", + "version": "5.5.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@athenna/core", - "version": "5.4.0", + "version": "5.5.0", "license": "MIT", "dependencies": { "pretty-repl": "^3.1.2", diff --git a/package.json b/package.json index 8270b9e..c8be327 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@athenna/core", - "version": "5.4.0", + "version": "5.5.0", "description": "One foundation for multiple applications.", "license": "MIT", "author": "João Lenon ", diff --git a/src/commands/BuildCommand.ts b/src/commands/BuildCommand.ts index a9d6471..98ca188 100644 --- a/src/commands/BuildCommand.ts +++ b/src/commands/BuildCommand.ts @@ -9,8 +9,8 @@ import { rimraf } from 'rimraf' import { tsc } from '@athenna/tsconfig/tsc' +import { Path, Color } from '@athenna/common' import { isAbsolute, join, parse } from 'node:path' -import { Path, Color, Module } from '@athenna/common' import { BaseCommand, Option } from '@athenna/artisan' import { copyfiles } from '@athenna/tsconfig/copyfiles' import { UndefinedOutDirException } from '#src/exceptions/UndefinedOutDirException' @@ -61,15 +61,8 @@ export class BuildCommand extends BaseCommand { () => tsc(tsConfigPath) ) - if (include.length) { - tasks.addPromise( - `Copying included paths to ${outDirName} folder: ${includedPaths}`, - () => copyfiles(include, outDir) - ) - } - if (this.vite) { - const vite = this.getVite() + const vite = await this.getVite() tasks.addPromise( `Compiling static files using ${Color.yellow.bold('vite')}`, @@ -81,6 +74,13 @@ export class BuildCommand extends BaseCommand { ) } + if (include.length) { + tasks.addPromise( + `Copying included paths to ${outDirName} folder: ${includedPaths}`, + () => copyfiles(include, outDir) + ) + } + await tasks.run() console.log() @@ -105,10 +105,8 @@ export class BuildCommand extends BaseCommand { return Path.pwd(Config.get('rc.commands.build.outDir')) } - public getVite() { - const require = Module.createRequire(import.meta.url) - - return require('vite') + public async getVite() { + return import('vite') } public async getViteConfig(vite: any) { diff --git a/src/commands/ServeCommand.ts b/src/commands/ServeCommand.ts index 6ac5847..7114db3 100644 --- a/src/commands/ServeCommand.ts +++ b/src/commands/ServeCommand.ts @@ -15,8 +15,7 @@ import { BaseCommand, Option } from '@athenna/artisan' export class ServeCommand extends BaseCommand { @Option({ signature: '-w, --watch', - description: - 'Use nodemon to watch the application and restart on changes (also turn on vite --watch if using it).', + description: 'Use nodemon to watch the application and restart on changes.', default: false }) public watch: boolean @@ -131,24 +130,16 @@ export class ServeCommand extends BaseCommand { await Module.resolve(entrypoint, Config.get('rc.parentURL')) } - public getVite() { - const require = Module.createRequire(import.meta.url) - - return require('vite') - } - - public getVitePluginRestart() { - const require = Module.createRequire(import.meta.url) - - return require('vite-plugin-restart') - } - public getNodemon() { const require = Module.createRequire(import.meta.url) return require('nodemon') } + public async getVite() { + return import('vite') + } + public async getViteConfig(vite: any) { const defaultConfig = { root: Path.pwd(),