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 🙏

© 2026 – Pkg Stats / Ryan Hefner

absolutify-paths-vite-react

v1.0.2

Published

Vite plugin to transform relative paths to absolute for WordPress theme development with HMR support

Readme

Absolutify Paths Vite Plugin

🇬🇧 English | 🇷🇺 Русский

Плагин для Vite, который помогает решить проблему с Hot Module Replacement (HMR) при разработке WordPress тем с использованием Vite. Плагин автоматически преобразует относительные пути в абсолютные, что необходимо для корректной работы HMR в WordPress.

Проблема

При разработке WordPress тем с использованием Vite, HMR может работать некорректно из-за того, что WordPress использует абсолютные пути для загрузки ресурсов, в то время как Vite по умолчанию использует относительные пути. Это приводит к тому, что обновления не применяются корректно.

Решение

Этот плагин автоматически преобразует относительные пути в абсолютные во время разработки, что позволяет HMR работать корректно в WordPress.

Особенности

  • Поддержка React компонентов
  • Автоматическое преобразование путей в JSX/TSX файлах
  • Корректная работа с динамическими импортами
  • Поддержка CSS модулей и других ассетов

Установка

npm install absolutify-paths-vite-react

Использование

  1. Импортируйте плагин в ваш vite.config.ts:
import { defineConfig } from 'vite';
import { absolutifyPaths } from 'absolutify-paths-vite-react';

export default defineConfig({
  plugins: [
    absolutifyPaths({
      strings: [
        // Пример: преобразование относительного пути в абсолютный
        ['/wp-content/themes/your-theme/assets/', 'http://localhost:8080/']
      ],
      enforce: 'pre', // Плагин будет выполняться до других плагинов
      apply: 'serve'  // Плагин будет работать только в режиме разработки
    })
  ]
});
  1. Настройте параметры плагина:
    • strings: массив пар строк для замены [исходная_строка, целевая_строка]
    • enforce: порядок выполнения плагина ('pre' | 'post' | undefined)
    • apply: когда применять плагин ('serve' | 'build' | undefined)

Пример конфигурации для WordPress темы с React

// vite.config.ts
import { defineConfig } from 'vite';
import { absolutifyPaths } from 'absolutify-paths-vite-react';
import react from '@vitejs/plugin-react';

export default defineConfig({
  plugins: [
    react(),
    absolutifyPaths({
      strings: [
        // Замените на ваши пути
        ['/wp-content/themes/your-theme/', 'http://localhost:5173/'],
        ['/wp-content/themes/your-theme/assets/', 'http://localhost:5173/assets/']
      ],
      enforce: 'pre',
      apply: 'serve'
    })
  ],
  server: {
    port: 5173,
    hmr: {
      host: 'localhost'
    }
  }
});

Пример использования с React компонентами

// components/MyComponent.tsx
import { useState } from 'react';
import styles from './MyComponent.module.css';

export const MyComponent = () => {
  const [count, setCount] = useState(0);

  return (
    <div className={styles.container}>
      <h1>Счетчик: {count}</h1>
      <button onClick={() => setCount(count + 1)}>
        Увеличить
      </button>
    </div>
  );
};

Конфигурация WordPress темы

Для включения HMR в вашей WordPress теме, вам нужно добавить следующий скрипт в файл header.php вашей темы:

<!-- React HMR -->
<script type="module">
    import RefreshRuntime from "http://localhost:3000/@react-refresh"
    RefreshRuntime.injectIntoGlobalHook(window)
    window.$RefreshReg$ = () => {}
    window.$RefreshSig$ = () => (type) => type
    window.__vite_plugin_react_preamble_installed__ = true
</script>
<!-- /React HMR -->

Этот скрипт необходим для корректной работы React HMR в WordPress. Он:

  • Импортирует React Refresh runtime с вашего Vite dev сервера
  • Внедряет необходимые HMR хуки в глобальный объект window
  • Настраивает требуемые функции React Refresh для обновления компонентов

Убедитесь, что:

  1. Размещаете этот скрипт в секции <head> вашего header.php
  2. Обновляете URL localhost:3000 в соответствии с портом вашего Vite dev сервера
  3. Сохраняете вызов функции wp_head() перед этим скриптом

Лицензия

MIT