Steps For Setup
- npm init vite-app jesusavina.com --template react-ts
- npm i -D autoprefixer
- npm i tailwindcss
- Create postcss.config.js
- Create tailwind.config.js
- Create .browserslistrc
Tips
- Add env NODE_ENV=production before vite build in the Package.json build script. This helps with postcss not detecting the env.
- Import tailwind css file in main/index.tsx and make sure index.html has <script type="module" src="/src/main.tsx"></script>.
- Utilized Google web font helper for smaller local fonts and browser support.
- Adding a prefatch link for my script increased my PageSpeed Insights score . Because Vite automatically inlines any file smaller than 4kb, I have to manually add this after the prod build.
- Adding a preload link for my css increased total blocking time even though it removed the render-blocking warning on PageSpeed Insights. I decided to not include the preload link for performance reasons. There may be a better way to solve this.
Production
- Vite uses Rollup for a production build
- Bundles all React code and purges unused code into 1 JS file under dist/_assets
- Bundles all CSS code and purges unused code into 1 css file under dist/_assets
- Adds an index.html file to dist with references to the js and css file which are under dist/_assets
Achievements
- PageSpeed Insights score of 100.
- Mozilla Observatory score of A+.