import EasyEditor from 'easyeditor';
npm install --save jquery easyeditor
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import { readdirSync,lstatSync } from 'fs';
import { resolve } from 'path';
function getFilesFromDir(dir) {
const filesToReturn = [];
function walkDir(currentPath) {
if(lstatSync(currentPath).isFile()){
filesToReturn.push(currentPath);
return;
}
const files = readdirSync(currentPath);
for (let i in files) {
console.log(files[i]);
const curFile = resolve(currentPath, files[i]);
if(lstatSync(curFile).isDirectory()){
walkDir(curFile);
continue;
}
const file = resolve(currentPath, files[i]);
filesToReturn.push(file);
}
}
walkDir(resolve(__dirname, dir));
return filesToReturn;
}
// Get all .css and .scss files in the directory
const js = getFilesFromDir('./resources/js');
const paths = [
...js,
'node_modules/jquery/dist/jquery.js',
'node_modules/jscroll/dist/jquery.jscroll.min.js',
"node_modules/easyeditor/src/easyeditor.css",
"node_modules/easyeditor/src/jquery.easyeditor.js"
]
export default defineConfig({
plugins: [
laravel({
input:paths,
refresh: true,
}),
],
build: {
rollupOptions: {
external: [
"js/modules/*",
],
include:[
'assets/js/utils.js'
]
}
}
});
That helps me to reduce the nessesary dependencies upon page load because vite (and webpack or silimar tools) do optimize Js code removing unsused functions, resulting faster page load.