AdonisJS ships with webpack encore to manage your frontend assets. This package provides a way to use Vite instead.
Note: the API may change between minor versions until we reach 1.0.
If you are creating a new project, choose false or N when you are asked if you want to configure webpack encore for compiling frontend assets.
If you are integrating this package in an existing project, you can remove webpack.config.js and any webpack related packages you may have in your project's dependencies.
npm install --save @91codes/adonis-vite
# or
yarn add @91codes/adonis-vite
npm install --save-dev vite
# or
yarn add -D vite
node ace configure @91codes/adonis-vite
You can start with the following. Feel free to customise it to your needs. You don't need react plugin if you aren't using react.
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import adonis from '@91codes/adonis-vite/build/plugins/adonis'
export default defineConfig({
plugins: [
react({ jsxRuntime: 'classic' }),
adonis({ input: 'resources/frontend/entrypoints/app.tsx' }),
],
})
Add the @vite
edge tag in your edge layout's head. You don't need @viteReactRefresh
if you aren't using react.
@viteReactRefresh()
@vite('resources/frontend/entrypoints/app.tsx')
public/hot
public/assets
public/manifest.json
Add the following scripts in package.json:
{
"scripts": {
"vite:dev": "npm run vite",
"vite:build": "npm run vite build"
}
}
Run these along with the default dev
and build
scripts.