Comments (9)
Hey there @stephenjason89 thanks for trying out fastify-vite
at such an early stage!
Changing root directory should be possible via the root
option in the latest release.
Also for compression you need to do it on Fastify's side via fastify-compress, because in fastify-vite, we're only using Vite's built-in server middleware for development, not production.
In any case, if you provide me with a GitHub repo for your attempt, I can look at it and get it working/fixed this coming weekend. On weekdays I'm afraid I'm too swamped with my day job.
Cheers!
from fastify-vite.
@ivanjeremic Vite's middleware is only useful for development purposes. It would be unnecessary overhead.
from fastify-vite.
@ivanjeremic that's what fastify-vite does already — it'll use the appropriate renderer package for production.
from fastify-vite.
Thank you so much @galvez,
Tried out fastify-compress and it is working pretty good. I will use this instead of vite-compress.
However, I can't seem to make the root option to work. I'm currently using fastify-vite: 2.1.3
Here's a repo of what i'm trying to achieve.
https://github.com/stephenjason89/FastifyVite
Thank you so much for creating such a powerful tool
EDIT 1:
npm run dev
It is kinda working now but i get an error
npm run build
throws me an error about index.html not found, because it is trying to find it in package.json level. It should be inside /client
dist folder should also be changed to /client/dist
Edit 2:
FINALLY npm run dev working, in this folder structure.
The errors that were being thrown before was related to the absolute path
__dirname+'/entry/client.js
I had to make it a dynamic path
note i had to make use of ( .. ) instead of ( . ) i don't know why the single ./entry/client.js resolves to an absolute path similar to __dirname+'/entry/client.js
Now my problem is when building,
it is trying to find index.html inside the directory of package.json not inside client folder
If i place index.html in the dir of package.json then it builds successfully
but dist folder is located together with package.json and passing
vite:{
build: {
assetsDir: 'client/assets',
outDir: 'client/dist',
},
}
Causes errors.
Also npm run serve is trying to find index.html inside /client which contradicts what npm run build wants
On my last commit, i tried to make vue-apollo to work. But not successful.
I just commented it out on main.js
from fastify-vite.
Hello, I'm sorry to bother you. But have you looked into it?
Thank you
from fastify-vite.
Hey there @stephenjason89 thanks for trying out
fastify-vite
at such an early stage!Changing root directory should be possible via the
root
option in the latest release.Also for compression you need to do it on Fastify's side via fastify-compress, because in fastify-vite, we're only using Vite's built-in server middleware for development, not production.
In any case, if you provide me with a GitHub repo for your attempt, I can look at it and get it working/fixed this coming weekend. On weekdays I'm afraid I'm too swamped with my day job.
Cheers!
Any reason not to use Vite middleware for production? I was experimenting and wondering why not?
from fastify-vite.
@ivanjeremic Vite's middleware is only useful for development purposes. It would be unnecessary overhead.
Ok so if I understand correctly if I want to build a nextjs like framework, It would make sense to use Vite built-in server only for development and fastify + vite build step for production correct?
from fastify-vite.
Hey guys. I faced the issue as well at least for version "fastify-vite-vue": "2.2.0-beta.2".
vite-plugin-compression is not working, looks like even not being called.
fasitfy-compress is not working for me. I would prefer to have static compressed files rather than to compress it on a fly.
So, I created a compression assets script which I integrated to our CI pipeline. I just created a scripts command in my package.json file:
"compress": "node compress-assets.js",
Thus, after running npm run build
you may run npm run compress
to generate gzip and brotli compressed files.
The script is written on NodeJS 14.x
compress-assets.js
const {createGzip, createBrotliCompress, constants} = require('zlib');
const {pipeline: pipelineStream} = require('stream');
const {promisify} = require('util');
const {createReadStream, createWriteStream} = require('fs');
const {opendir} = require('fs/promises');
const {join, extname} = require('path');
const pipeline = promisify(pipelineStream);
function changeExtension(filepath, toExt) {
return `${filepath}${toExt}`;
}
async function compressAssets() {
const assetsPath = './dist/client/assets';
const dir = await opendir(assetsPath);
for await (const dirent of dir) {
if (!dirent.isFile()
|| extname(dirent.name) === '.br'
|| extname(dirent.name) === '.gz') {
continue;
}
console.log(`Start processing ${dirent.name}`);
const filepath = join(assetsPath, dirent.name);
const outputGzipFilepath = changeExtension(filepath, '.gz');
const outputBrotliFilepath = changeExtension(filepath, '.br');
const gzip = createGzip({
level: constants.Z_BEST_COMPRESSION
});
const brotli = createBrotliCompress({
level: constants.Z_BEST_COMPRESSION
});
await pipeline(
createReadStream(filepath),
gzip,
createWriteStream(outputGzipFilepath)
);
await pipeline(
createReadStream(filepath),
brotli,
createWriteStream(outputBrotliFilepath)
);
}
}
compressAssets()
.then(() => console.log('Assets have been compressed'));
from fastify-vite.
This has been fixed in the latest version. You either use vite.config.js
or options.vite
.
I'll add a mechanism to easily eject the bundled vite.config.js
from renderer adapters, but for now know that if you manually provide vite.config.js
, it'll work again.
from fastify-vite.
Related Issues (20)
- Files in /public folder are not served in production mode HOT 4
- Error on Windows: TypeError: Cannot read properties of null (reading 'replace')
- Websocket can not connect when using https fastify
- If vites config contains `defineConfig` with callback, then SSR is broken HOT 3
- How to configure multi-page entry
- Issues running with fastify-compress HOT 4
- Serve static assets from ssr builds in production mode HOT 2
- TypeError [ERR_INVALID_ARG_TYPE]: The "paths[0]" argument must be of type string
- Trace: The CJS build of Vite's Node API is deprecated
- Conflicting websockets between vite and `@fastify/websocket` causing infinite redirects HOT 1
- [react][windows] React Starter Template does not start on Windows HOT 4
- How to use Vue plugins like instance.use(...) HOT 4
- NPM install fails with 'edgesout' error HOT 3
- [SPA] allowing passing additional context to the render function HOT 3
- mts file extension is not supported for vite.config HOT 3
- @fastify/vue Smart Import doesn't resolve path in windows HOT 5
- How to config fastify-vite in a Electron Vite project HOT 1
- SPA Documentation / Examples HOT 5
- Move `fastify` and `vite` to peer dependencies
- Missing `fastify-plugin` dependency
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fastify-vite.