hotwired / stimulus

A modest JavaScript framework for the HTML you already have
https://stimulus.hotwired.dev/
MIT License
12.73k stars 426 forks source link

Vite and stimulus invalid unicode #798

Closed JSlomian closed 1 month ago

JSlomian commented 1 month ago

So I added vite from pentatrion after updating symfony from 5.4 to 6.4 to modernize company application. However stimulus keeps being added to alot of files and it causes errors if the file starts with u because it inserts \u.

This is what's being inserted when running vite

if (import.meta.hot) {
  import.meta.hot.accept(newModule => {
    if (!window.$$stimulusApp$$) {
      console.warn('Stimulus app not available. Are you creating app with startStimulusApp() ?');
      import.meta.hot.invalidate();
    } else {
      window.$$stimulusApp$$.register('vendor\symfony\ux-vue\assets\dist\render', newModule.default);
    }
  })
}

This is my vite.config.js

import {defineConfig} from "vite";
import symfonyPlugin from 'vite-plugin-symfony';
import { viteStaticCopy} from "vite-plugin-static-copy";
import vuePlugin from "@vitejs/plugin-vue";
import * as path from "node:path";
import vueDevTools from "vite-plugin-vue-devtools"

const isBuild = process.argv.includes('build');

export default defineConfig({
  root: '.',
  base: isBuild ? '/sklep/build' : '/build',
  assetsInclude: ['**/*.doc'],
  resolve: {
    extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.scss', '.css', '.vue'],
    alias: {
      '@': path.resolve(__dirname, './assets/'),
      '~': path.resolve(__dirname, 'node_modules')
    }
  },
  plugins: [
    vueDevTools(),
    vuePlugin(),
    symfonyPlugin({
      refresh: ["templates/**/*.twig"],
      stimulus: true
    }),
    viteStaticCopy({
      targets: [
        {
          src: './assets/documents/*.{doc,docx}',
          dest: 'assets/documents'
        }
      ]
    })
  ],
  build: {
    assetsInlineLimit: 0,
    manifest: true,
    rollupOptions: {
      input: {
        app: "./assets/app.js",
        categoryViewCart: "./assets/categoryViewCart.js",
        singleProduct: "./assets/singleProduct.js",
        newProductsCart: "./assets/newProductsCart.js",
        shopRegister: "./assets/shopRegister.js",
        passwordEyeToggle: "./assets/passwordEyeToggle.js",
        userProfile: "./assets/userProfile.js"
      },
    },
    outDir: 'public/build',
  },
});

the part in app.js

import { registerVueControllerComponents } from "vite-plugin-symfony/stimulus/helpers/vue"
import { startStimulusApp, registerControllers } from "vite-plugin-symfony/stimulus/helpers"

registerVueControllerComponents(import.meta.glob('./vue/controllers/**/*.vue'))

const app = startStimulusApp();
registerControllers(
  app,
  import.meta.glob(
    "./controllers/*_controller.js",
    {
      query: "?stimulus",
      eager: true,
    },
  ),
);

I don't remember this but must've been from recipes

{
    "controllers": {
        "@symfony/ux-vue": {
            "vue": {
                "enabled": true,
                "fetch": "eager"
            }
        }
    },
    "entrypoints": []
}

My vue components are not displayed as well using vue_component I have to manually createApp and mount it and disabling stimulus breaks everythings. My office pc is running windows.

If this is not the right place I'm sorry and let me know where I should paste it instead. Thanks!