- Added support for uploading and compressing GLB models using Draco in the backoffice. - Implemented commands for importing and re-compressing 3D models. - Updated model resource to handle 3D model uploads and validations. - Introduced a new script for compressing GLB files with Draco. - Modified Vite configuration to remove GLB files from the build output. - Updated package dependencies to include GLTF-transform libraries for handling 3D models. - Added tests to ensure proper functionality of 3D model handling and compression.
80 lines
2.7 KiB
JavaScript
80 lines
2.7 KiB
JavaScript
import { defineConfig } from 'vite';
|
|
import path from 'path';
|
|
import { viteStaticCopy } from 'vite-plugin-static-copy';
|
|
import { ViteMinifyPlugin } from 'vite-plugin-minify'
|
|
import fs from 'node:fs/promises';
|
|
// Cifratura dei modelli, pronta ma non attiva: vedi vite-plugins/encrypt-models.js.
|
|
// import encryptModels from './vite-plugins/encrypt-models.js';
|
|
|
|
// Nessun .glb va online dalla build (es. i file archiviati in assets/data): i modelli 3D li serve il
|
|
// backoffice, già compressi con Draco. Parte dopo il writeBundle di vite-plugin-static-copy.
|
|
function rimuoviGlb() {
|
|
let outDir;
|
|
return {
|
|
name: 'kreios-rimuovi-glb',
|
|
apply: 'build',
|
|
configResolved(config) {
|
|
outDir = config.build.outDir;
|
|
},
|
|
writeBundle: {
|
|
sequential: true,
|
|
order: 'post',
|
|
async handler() {
|
|
const files = await fs.readdir(path.join(outDir, 'assets'), { recursive: true }).catch(() => []);
|
|
await Promise.all(files
|
|
.filter((file) => file.toLowerCase().endsWith('.glb'))
|
|
.map((file) => fs.rm(path.join(outDir, 'assets', file))));
|
|
},
|
|
},
|
|
};
|
|
}
|
|
|
|
export default defineConfig({
|
|
// Il configuratore è servito da Laravel sotto /configuratore/ (stessa origine dell'API):
|
|
// la build finisce direttamente in backoffice/public/configuratore.
|
|
base: '/configuratore/',
|
|
root: 'src',
|
|
// root è 'src', ma i file .env/.env.production vivono nella root del repo (accanto a build.sh).
|
|
envDir: path.resolve(__dirname),
|
|
build: {
|
|
outDir: path.resolve(__dirname, 'backoffice/public/configuratore'),
|
|
minify: true,
|
|
cssMinify: true,
|
|
|
|
emptyOutDir: true,
|
|
rollupOptions: {
|
|
input: {
|
|
main: path.resolve(__dirname, 'src/index.html')
|
|
}
|
|
},
|
|
},
|
|
plugins: [
|
|
viteStaticCopy({
|
|
targets: [
|
|
{
|
|
// I modelli 3D sono gestiti dal backoffice (caricati e compressi con Draco):
|
|
// quelli in src/assets/models servono solo a `php artisan modelli3d:importa`.
|
|
src: ['assets/*', '!assets/models'],
|
|
dest: 'assets'
|
|
}
|
|
]
|
|
}),
|
|
rimuoviGlb(),
|
|
ViteMinifyPlugin({
|
|
minify: {
|
|
removeComments: true,
|
|
collapseWhitespace: true,
|
|
minifyCSS: true,
|
|
minifyJS: true,
|
|
minifyURLs: true
|
|
}
|
|
})
|
|
],
|
|
resolve: {
|
|
alias: {
|
|
'three': path.resolve(__dirname, 'node_modules/three'),
|
|
'@': path.resolve(__dirname, 'src')
|
|
}
|
|
}
|
|
});
|