egoist / vite-plugin-mix

Adding backend API to your Vite app.
https://github.com/egoist/vite-plugin-mix
MIT License
228 stars 17 forks source link

Is seems not working if base is set #45

Open 7Red4 opened 1 year ago

7Red4 commented 1 year ago

Hi!

My situation is I'm going to serve my project which is only accessable under a path e.g. https://example.com/prefix-path/ So I set the base in my config image

After I build and run node /build/server.js I can view my app correctly and keep getting this error below

Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.

Wonder am I using this wrong or if there have any solution for this.

thanks.

m-kolomoyets commented 3 months ago

Same issue, but getting the different error while starting the dev build:

import { defineConfig, loadEnv } from 'vite';
import react from '@vitejs/plugin-react';
import eslint from 'vite-plugin-eslint';
import { visualizer } from 'rollup-plugin-visualizer';
import mix from 'vite-plugin-mix';

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
    const env = loadEnv(mode, process.cwd(), '');

    return {
        plugins: [
            react(),
            eslint({ exclude: ['**/virtual:/**', '**/node_modules/**'] }),
            visualizer({
                filename: './tmp/bundle-visualizer.html',
            }),
            mix({
                handler: './api/router.ts',
            }),
        ],
        base: env.VITE_BASE_PUBLIC_PATH,
        test: {
            environment: 'jsdom',
        },
        resolve: {
            alias: [{ find: '@', replacement: '/src' }],
        },
        server: {
            port: 3000,
        },
        preview: {
            port: 4173,
        },
    };
});

CleanShot 2024-03-25 at 12  09 27@2x