caoxiemeihao / nuxt-electron

Integrate Nuxt and Electron
MIT License
191 stars 21 forks source link

nuxt dev preload script not loaded #73

Closed Venipa closed 7 months ago

Venipa commented 7 months ago

im unable to load the preload script into the window,

BrowserWindow config:

// dont mind the createWindow function
const win = await createWindow("/", {
    minWidth: 1280,
    width: 1280,
    minHeight: 720,
    height: 720,
    webPreferences: {
      preload: "dist-electron/api.js"
    }
  });

nuxt.config.ts

export default defineNuxtConfig({
  devtools: { enabled: false },
  modules: ['nuxt-electron', '@nuxtjs/tailwindcss', "shadcn-nuxt", "nuxt-icon", "@nuxt/image", '@nuxtjs/i18n'],
  srcDir: "src/",
  css: ["~/assets/css/tailwind.css", "~/assets/css/app.scss"],
  ssr: false,
  experimental: { appManifest: false },
  electron: {
    build: [
      {
        // Main-Process entry file of the Electron App.
        entry: 'src/electron/main.ts',
      },
      {
        entry: 'src/electron/preload/api.ts',
        onstart(args) {
          args.reload();
        },
      }
    ],
  },
  shadcn: {
    /**
     * Prefix for all the imported component
     */
    prefix: '',
    /**
     * Directory that the component lives in.
     * @default "./components/ui"
     */
    componentDir: 'src/components/ui'
  },
  image: {
    dir: "images/"
  },
  i18n: {
    locales: [
      {
        code: "en",
        file: "en.json"
      }
    ],
    defaultLocale: "en",
    langDir: "translations/"
  }
})

package.json:


  "name": "nuxt-app",
  "private": true,
  "type": "module",
  "main": "dist-electron/main.js",
  "version": "0.1.0",
  "scripts": {
    "build": "nuxt build",
    "dev": "nuxt dev",
    "generate": "nuxt generate",
    "preview": "nuxt preview",
    "postinstall": "nuxt prepare"
  },
  "dependencies": {
    "@radix-icons/vue": "^1.0.0",
    "@vee-validate/zod": "^4.12.6",
    "@vueuse/core": "^10.9.0",
    "class-variance-authority": "^0.7.0",
    "clsx": "^2.1.0",
    "electron-store": "^8.2.0",
    "embla-carousel": "^8.0.2",
    "embla-carousel-vue": "^8.0.2",
    "express": "^4.19.2",
    "got": "^14.2.1",
    "gotql": "^2.1.0-alpha1",
    "keytar": "^7.9.0",
    "lodash-es": "^4.17.21",
    "nuxt": "3.10.2",
    "radix-vue": "^1.7.0",
    "tailwind-merge": "^2.2.2",
    "tailwindcss-animate": "^1.0.7",
    "v-calendar": "^3.1.2",
    "vaul-vue": "^0.1.0",
    "vee-validate": "^4.12.6",
    "vue": "^3.4.21",
    "vue-router": "^4.3.0",
    "vue-sonner": "^1.1.2",
    "winston": "^3.13.0",
    "zod": "^3.22.4"
  },
  "devDependencies": {
    "@nuxt/image": "^1.5.0",
    "@nuxtjs/i18n": "^8.3.0",
    "@nuxtjs/tailwindcss": "^6.11.4",
    "@types/express": "^4.17.21",
    "@types/got": "^9.6.12",
    "@types/keytar": "^4.4.2",
    "@types/lodash-es": "^4.17.12",
    "@types/node": "^20.12.7",
    "electron": "^29.3.0",
    "electron-builder": "^24.13.3",
    "nuxt-electron": "^0.7.0",
    "nuxt-icon": "^0.6.10",
    "sass": "^1.75.0",
    "shadcn-nuxt": "^0.10.2",
    "vite-plugin-electron": "^0.28.4",
    "vite-plugin-electron-renderer": "^0.14.5",
    "webpack-env": "^0.8.0"
  },
  "resolutions": {
    "nuxi": "3.10.1"
  }
Venipa commented 7 months ago

Absolute paths work it seems

caoxiemeihao commented 7 months ago
image

https://www.electronjs.org/docs/latest/api/structures/browser-window-options