rockiger / reactpress

Plugin that lets you easily create, build and deploy React apps into your existing WordPress sites.
https://rockiger.com/en/reactpress/
GNU General Public License v2.0
50 stars 6 forks source link

Vite App images path #56

Open cif95 opened 3 months ago

cif95 commented 3 months ago

I developed a vite app in reactpress plugin and everything is working fine. However the app returns 404 for all images path. I tried to upload images either statically either in public folder, but it did not work in either cases. I set the variable base in vite.config.js to match the site domain, and upload the package json with the script "build": "vite build --base=/wp-content/reactpress/apps/[appName]/dist".

Can you please advise on how to make images work in vite environment ?

rockiger commented 2 months ago

I don't know if --base has an effect. The dist-folder should be set in the vite.config.js. Like this:

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

// https://vitejs.dev/config/
export default defineConfig(({ command }) => {
  if (command === 'build') {
    return {
      base: "/wp-content/reactpress/apps/tmp/dist/",
      plugins: [react()],
    }
  } else {
    return {
      plugins: [react()],
    }
  }
})

I tested it and it worked flawlessly.