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

@webfox/laravel-vite

v1.2.0

Published

Webfox's fork of laravel-vite.

Downloads

4

Readme

Webfox Vite

Webfox's custom vite set up. Below is a guide on how to switch an encore project to using vite.

Authors

Matthew Hailwood, (Mad Dev who made the plugin)
Jim Hulena, (The guy who wrote the guide)

How to switch old laravel projects using encore

Disclaimer: This may not be a "one size fits all", there will likely be other issues you encounter, though we are more than happy to help.

  1. npm install @vitejs/plugin-react vite-plugin-restart
  2. npm install react-dom @inertiajs/inertia-react @inertiajs/progress
  3. refactor app.js to app.tsx
  4. copy and paste below into app.tsx. Ensure you have FormErrorContextProvider and InitialApplicationContext
import MainLayout from './Layouts/MainLayout';
import {initInertiaApp} from 'Support/init';
import 'Style/app.css';

initInertiaApp({
  resolve: async name => {
    const comps = import.meta.glob('./Pages/**/*.jsx'); //Can be jsx or tsx depending on your langauge preference
    const match = comps[`./Pages/${name}.jsx`]; //same as above comment
    return (await match()).default;
  },
  layout: MainLayout,
});
  1. Create init.tsx in Support directory
  2. Copy and paste below into init.tsx
import {Inertia} from '@inertiajs/inertia';
import {createInertiaApp, PageResolver} from '@inertiajs/inertia-react';
import {InertiaProgress, ProgressSettings} from '@inertiajs/progress';
import * as React from 'react';
import {createRoot} from 'react-dom/client'
import {ComponentType, createElement, PropsWithChildren, ReactElement, StrictMode} from 'react';
import {FormErrorContextProvider, InitialApplicationContext} from './Contexts';
import 'Support/yupExtensions';

// export const initGoogleAnalytics = () => {
//   if (typeof window.gtag === 'function') {
//     let initialPageView = true;
//     Inertia.on('navigate', (event) => {
//       if (initialPageView) {
//         initialPageView = false;
//       } else {
//         window.gtag('event', 'page_view', {
//           'page_location': event.detail.page.url,
//         });
//       }
//     });
//   }
// };
//
// export const initErrorTracking = async () => {
//   if (window.sentryDsn) {
//     const Sentry = await import('@sentry/react');
//     const {BrowserTracing} = await import('@sentry/tracing');
//
//     Sentry.init({
//       dsn: window.sentryDsn,
//       integrations: [new BrowserTracing()],
//       environment: window.sentryEnvironment,
//       tracesSampleRate: window.sentryTracesSampleRate,
//     });
//   }
// };

export const initInertiaApp = ({
  resolve,
  layout: MainLayout,
  analytics = true,
  errorTracking = true,
  inertiaProgress = true,
}: {
  resolve: PageResolver;
  layout: ComponentType<PropsWithChildren>;
  analytics?: boolean;
  errorTracking?: boolean;
  inertiaProgress?: boolean | ProgressSettings;
}) => {
  // if (errorTracking) {
  //   initErrorTracking();
  // }
  //
  //
  // if (analytics) {
  //   initGoogleAnalytics();
  // }

  if (inertiaProgress) {
    InertiaProgress.init(typeof inertiaProgress === 'boolean' ? {
      showSpinner: true,
    } : inertiaProgress);
  }

  return createInertiaApp < Window['inertiaInitialPageData']['props'] > ({
    resolve,
    page: window.inertiaInitialPageData,
    setup({el, App, props}) {
      createRoot(el).render((
        <StrictMode>
          <InitialApplicationContext.Provider value={{application: props.initialPage.props.application}}>
            <App {...props}>
              {({key, props, Component}) => {
                // @ts-ignore
                const componentLayout: (page: ReactElement) => ReactElement | Array<(page: ReactElement) => ReactElement> = Component.layout;
                const page = createElement(Component, {key, ...props});
                let children;

                if (Array.isArray(componentLayout)) {
                  children = componentLayout.concat(page).reverse().reduce((children, Layout) => createElement(Layout, {children}));
                } else if (typeof componentLayout === 'function') {
                  children = componentLayout(page);
                } else {
                  children = <MainLayout children={page}/>;
                }

                return (
                  <FormErrorContextProvider>
                    {children}
                  </FormErrorContextProvider>
                );
              }}
            </App>
          </InitialApplicationContext.Provider>
        </StrictMode>
      ));
    },
  });
};
  1. create vite.config.ts in root directory
  2. copy below into vite.config.ts
import react from '@vitejs/plugin-react';
import laravel from '@webfox/laravel-vite';
import {defineConfig} from 'vite';
import viteRestart from 'vite-plugin-restart';

export default defineConfig({
  plugins: [
    laravel(['resources/app/js/app.tsx',]),
    react(),
    viteRestart({
      restart: 'tsconfig.json',
    }),
  ],
  server: {
    host: 'localhost',
    hmr: {
      host: 'localhost',
    },
    https: {
      key: process.env.WEBPACK_KEY,
      cert: process.env.WEBPACK_CERT,
    },
  },
  css: {
    postcss: {
      plugins: [
        require('postcss-import')(),
        require('tailwindcss')(),
        require('autoprefixer')(),
      ],
    },
  },
});
  1. Replace 'resources/app/js/app.tsx' with the path to your app.tsx
  2. Add @viteReactRefresh and @vite('resources/app/js/app.tsx') to the body of your app.blade.php
  3. Remove all Encore related code from app.blade.php
  4. In helper.php remove function encore
  5. Select all js files in PHPStorm, right click and select "Override file type" and search for jsx. (All files need to be jsx)
  6. In package.json replace "Scripts" with below
 "scripts": {
    "hot": "cross-env NODE_ENV=development vite",
    "prod": "cross-env NODE_ENV=production vite build"
  },
  1. create tsconfig.json in root directory
  2. copy and paste below into tsconfig.json
{
  "include": [
    "resources/app/js/**/*",
    "resources/app/css/**/*",
    "resources/app/images/**/*"
  ],
  "compilerOptions": {
    "rootDir": ".",
    "incremental": true,
    "allowJs": true,
    "noErrorTruncation": true,
    "lib": [
      "ESNext",
      "DOM"
    ],
    "target": "ESNext",
    "module": "ESNext",
    "sourceMap": true,
    "isolatedModules": true,
    "experimentalDecorators": true,
    "moduleResolution": "Node",
    "noImplicitOverride": true,
    "strictNullChecks": true,
    "esModuleInterop": true,
    "jsx": "react-jsx",
    "paths": {
      "Components": [
        "./resources/app/js/Components"
      ]
    }
  }
}
  1. replace path object with your aliases in the same format as Components