GithubHelp home page GithubHelp logo

Comments (7)

jrj2211 avatar jrj2211 commented on June 18, 2024 2

I found that I can override that setting in vite.main.config.js:

// https://vitejs.dev/config
export default defineConfig({
  resolve: {
    ...
  },
  build: {
    lib: {
      formats: ["es"],
    },
  },
});

I have another issue now though, as in esm __dirname is not available. This is needed to specify the index.html path and the preload file. I changed it to:

const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
...
mainWindow.loadFile(path.join(dirname, "index.html"));

However, Vite replaces import.meta.url with self.location and then Vite errors out ReferenceError: self is not defined.

If I replace them with relative paths, it loads the files but warns it wants an absolute path for preload.js.

Guessing some sort of MAIN_WINDOW_PRELOAD_VITE_ENTRY and MAIN_WINDOW_VITE_ENTRY will need to be generated outside of Vite similar to how the webpack plugin works?

from forge.

Sahasrara avatar Sahasrara commented on June 18, 2024 1

The combination of svelte + vite + electron + forge doesn't seem to work unless we have ESM support.

from forge.

jrj2211 avatar jrj2211 commented on June 18, 2024 1

Aweome! I haven't had a chance to try your suggestion but I'm starting a new project tomorrow and might mess around with it more. Hopefully the official support comes soon but good to know its coming by default soon!

from forge.

sparecycles avatar sparecycles commented on June 18, 2024

+1.

Thanks for your investigation!

I wonder if you tried import.meta.resolve(...)? It's both more to the point and perhaps vite doesn't try to mess with it?

I'm brought here trying to use both @sveltejs/vite-plugin-svelte which is esm-only, (and so it requires "type": "module" in package.json), and this is tripping me up.

I think I can slap an dist-electron/package.json in with { "type": "commonjs" } as a work-around but it feels a bit horrid. 😉

from forge.

caoxiemeihao avatar caoxiemeihao commented on June 18, 2024

The combination of svelte + vite + electron + forge doesn't seem to work unless we have ESM support.

You can try to this 👉 #3309

The next version of Vite plugin will be use "type"="module" by default, coming soon...

from forge.

Sahasrara avatar Sahasrara commented on June 18, 2024

Is this something that's planned? I'm hoping to use Forge with Svelte + Vite (not SvelteKit).

from forge.

sparecycles avatar sparecycles commented on June 18, 2024

The "horrid" workaround I suggested seems to be working for me. I've got vite+forge+tailwind+typescript+svelte+melt+workers+import("node:module").register (node20, electron29-alpha) working fine.

from forge.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.