vp-runtime-helper

raw JSON →
1.0.10 verified Mon Apr 27 auth: no javascript

vp-runtime-helper v1.0.10 is a Vite plugin development utility providing helper functions for writing Vite plugins. It simplifies common tasks like path manipulation, environment detection, and plugin configuration. Released under the MIT license with TypeScript types included, it targets Vite >=3.1.0 and Node >=14.18.0. Key differentiators: designed specifically for Vite plugin authors, lightweight with zero runtime dependencies, and offers a cohesive set of utilities optimized for Vite's plugin system.

error Cannot find module 'vp-runtime-helper' or its corresponding type declarations.
cause The package may not be installed or the project is using TypeScript but missing type declarations for a CommonJS module.
fix
Install the package: npm install vp-runtime-helper. If using TypeScript, ensure 'esModuleInterop' is enabled in tsconfig.json, or use a default import with 'allowSyntheticDefaultImports'.
error TypeError: vprh.isDev is not a function
cause The imported object is not the default export (e.g., using named import incorrectly).
fix
Use the correct default import: import vprh from 'vp-runtime-helper'. Then call vprh.isDev()
error Uncaught SyntaxError: The requested module 'vp-runtime-helper' does not provide an export named 'HelperFunction'
cause Using an incorrect named export name or the import syntax is wrong in a browser context.
fix
Check available exports in the documentation. Use named imports correctly: import { HelperFunction } from 'vp-runtime-helper'. If bundling for browser, ensure the package is compatible and not using Node.js APIs.
gotcha The package is designed for Vite plugin development; using it outside of a Vite context may cause unexpected behavior.
fix Ensure you are using this only inside Vite plugins or hooks.
gotcha Some helper functions may rely on Vite's internal structures which can change between Vite versions.
fix Pin the vp-runtime-helper version to a specific one that works with your Vite version, and test after upgrading Vite.
deprecated The legacy function 'vprh.legacyHelper' is deprecated in v1.0.5 and removed in v1.0.10.
fix Use the recommended alternative: vprh.newHelper or update to v1.0.10 and adapt your code accordingly.
npm install vp-runtime-helper
yarn add vp-runtime-helper
pnpm add vp-runtime-helper

Demonstrates how to import and use the default export and two helper functions (resolveAlias, isDev) in a Vite plugin written in TypeScript.

import vprh from 'vp-runtime-helper'
import type { Plugin } from 'vite'

export default function myPlugin(): Plugin {
  return {
    name: 'my-plugin',
    config(config) {
      console.log(vprh.resolveAlias(config.resolve?.alias))
      if (vprh.isDev(config)) {
        console.log('Development mode')
      }
      return config
    }
  }
}