npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@promoboxx/react-scripts-vite

v0.2.5

Published

An almost drop-in replacement for react-scripts, but based on Vite.

Downloads

27

Readme

react-scripts-vite

An almost drop-in replacement for react-scripts, but based on Vite.

Features

  • svgr
  • TypeScript paths
  • TypeScript type checking
  • ESLint linting
  • PWA support
  • process.env
  • Vitest

Getting Started

Install @promoboxx/react-scripts-vite:

npm install --save-dev @promoboxx/react-scripts-vite

Edit your vite.config.ts:

import { viteConfig } from '@promoboxx/react-scripts-vite'

export default viteConfig

If you're using TypeScript, you'll want to load the client types. This will clear up any errors when accessing import.meta.hot, or when importing an image.

Put this in src/react-scripts-vite.d.ts:

/// <reference types="@promoboxx/react-scripts-vite/dist/client" />

Customization

react-scripts-vite exports both a viteConfig function and an pluginOptions object. The pluginOptions object lets you customize the included plugins. And if you'd like to add your own plugins, or change any of the vite config, you're free to do so.

Changing included plugin options

import { viteConfig, pluginOptions } from '@promoboxx/react-scripts-vite'

// Setting one of the properties to `false` turns off the plugin entirely.
pluginOptions.react = false
pluginOptions.pwa = {
  registerType: 'autoUpdate',
}

export default viteConfig

Changing included vite config

import { defineConfig } from 'vite'
import { viteConfig, pluginOptions } from '@promoboxx/react-scripts-vite'

// Disable SVGR.
pluginOptions.svgr = false
// Change PWA config.
pluginOptions.pwa = {
  registerType: 'autoUpdate',
}

export default defineConfig(async (env) => {
  // await is needed so the type isn't `UserConfig | Promise<UserConfig>`
  const config = await viteConfig(env)

  config.plugins = [
    ...(config.plugins || []),
    // Add whatever plugins you want.
    YourVitePlugin(),
  ]

  config.build = {
    ...config.build,
    // Turn off sourcemaps.
    sourcemap: false,
  }

  return config
})

Migrating from react-scripts

Should be very straightforward. For application code, everything should be supported out of the box.

index.html

Vite expects your index.html to live at the root directory, not in public/

mv public/index.html ./

Remove any references to %PUBLIC_URL%, vite correctly sets the base path for you.

Sass

Sass isn't included as per Vite's recommendation. You can add pre-processors to your projects if you wish.

Tests

react-scripts-vite uses Vitest instead of Jest. Vitest has a jest-compatible interface, accessible via vi.

The path to the test setup file has changed:

mkdir -p src/test/
mv src/setupTests.ts src/test/setup.ts