Skip to content

nongbit/codeigniter-vite

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Codeigniter Vite

Integrate Vite to CodeIgniter 4.

Setup

Download package using composer.

composer require nongbit/codeigniter-vite

Run command to initiate vite.

php spark vite:init

Open APPPATH/Config/Vite.php.

<?php

namespace Config;

use CodeIgniter\Config\BaseConfig;

class Vite extends BaseConfig
{
    public array $entryPoints = [
        '' => 'Views/assets/js/app.js',
    ];
}

Usage

Inside your view, call vite_url().

If the vite server is active then vite_url() will produce code like the following.

<script type="module" src="http://localhost:5173/app/Views/assets/js/app.js"></script>

If manifest.json is found then vite_url() will read the file and generate the appropriate html code, something like this:

<link rel="stylesheet" href="http://localhost/assets/app.css">
<script type="module" src="http://localhost/assets/app.js">