Closed drylian closed 4 months ago
My Personal Confs (created and tested) vite.config.ts
import { dirname, resolve } from 'path'
import { defineConfig } from 'vite'
import { createRequire } from 'module';
import { fileURLToPath } from 'url';
const require = createRequire(import.meta.url);
const { externals } = require('rollup-plugin-node-externals');
const isDev = process.env.NODE_ENV?.startsWith("dev") ? true : false;
export default defineConfig({
plugins:[
{
enforce: 'pre',
...externals(),
}
],
resolve: {
alias: {
'@': resolve(dirname(fileURLToPath(import.meta.url)), 'src'),
},
},
build: {
minify:isDev ? false : true,
sourcemap: isDev? true : false,
outDir:"omp/js",
lib: {
entry: resolve(__dirname, 'src/main.ts'),
formats: ["cjs"]
},
rollupOptions: {
output: {
globals: {
vue: 'Vue', // remove required index.html in build
},
},
},
},
})
The most current versions of this module work too, but I left the old one to have better support for node 16 Devdeps:
{
"rollup-plugin-node-externals": "^5.1.3",
"vite": "^4",
}
scripts:
{
"js:dev": "cross-env NODE_ENV=development vite build --watch", // for development
"js:build": "tsc && cross-env NODE_ENV=production vite build" // for build tsc for types
}
tsconfig: only not use distOut dir, for tsc build not make files](tsconfig: just don't use outDir, so tsc build doesn't create files, after all Vite will do that)
Vite will generate a file with the name package.json, example { name:"omp-server" } > Vite.outDir + omp-server.cjs
Thank you for your suggestion, but for now I won't consider replacing rollup with vite. I may consider it in the future.
I think rollup with esbuild is a good compilation solution for now, Vite is indeed suitable for building front-end Vue applications, but I haven't tried using it to build back-end applications yet.
How much improvement in performance did you see after switching to vite compared to the previous compilation?
I just did a test with the same sources (infernus/starter) and now it seems to me that the two are almost the same thing, what would change would just be that rollup needs 7 deps to work (3types and 4 deps) and vite 2(deps), but I don't think it would affect much when I did it with Vite it was with Vite in my gamemode so that could be why I felt a difference in the compilations, but the results are there
Rollup Compillation time (first initiation) second initiation roullup in another comps (77ms/min ~ 371ms/max) // sample editions
Vite Compillation time (first) Vite Compilation time (second) vite in another comps (65ms/min ~ 301ms/max) // sample editions
I am testing this Samp-Node and Infernus and it really seemed very good, the use of Rollup and the time of compilation seems more time consuming, would it not be better to use Vite?