Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何使用vite创建2个html页面? #237

Open
zzxdt opened this issue Apr 29, 2024 · 0 comments
Open

如何使用vite创建2个html页面? #237

zzxdt opened this issue Apr 29, 2024 · 0 comments

Comments

@zzxdt
Copy link

zzxdt commented Apr 29, 2024

结合了插件 配置vite成这样:
import { fileURLToPath } from 'url'
import { defineConfig, loadEnv } from 'vite'
import ElectronPlugin, { ElectronOptions } from 'vite-plugin-electron'
import RendererPlugin from 'vite-plugin-electron-renderer'

import VuetifyPlugin from 'vite-plugin-vuetify'
import VueJsx from '@vitejs/plugin-vue-jsx'
import Vue from '@vitejs/plugin-vue'
import { rmSync } from 'fs'
import { resolve, dirname } from 'path'
import { builtinModules } from 'module'

const isDevEnv = process.env.NODE_ENV === 'development'

export default defineConfig(({ mode }) => {
process.env = {
...(isDevEnv
? {
ELECTRON_ENABLE_LOGGING: 'true'
}
: {}),
...process.env,
...loadEnv(mode, process.cwd())
}

rmSync('dist', { recursive: true, force: true })

const electronPluginConfigs: ElectronOptions[] = [
{
entry: '../main/index.ts',
onstart({ startup }) {
startup()
},
vite: {
build: {
assetsDir: '.',
outDir: 'dist/main',
rollupOptions: {
plugins: [
require('@rollup/plugin-alias')({
entries: [{ find: '@', replacement: resolve(__dirname, 'src') }]
})
],
external: ['electron', ...builtinModules, 'koffi']
},
}
}
},
{
entry: '../preload/index.ts',
onstart({ reload }) {
reload()
},
vite: {
resolve: {
alias: {
'@': resolve(dirname(fileURLToPath(import.meta.url)), 'src')
}
},
build: {
outDir: 'dist/preload'
}
}
}
]

if (isDevEnv) {
electronPluginConfigs.push({
entry: 'src/main/index.dev.ts',
vite: {
build: {
outDir: 'dist/main'
}
}
})
}

return {
define: {
VUE_I18N_FULL_INSTALL: true,
VUE_I18N_LEGACY_API: false,
INTLIFY_PROD_DEVTOOLS: false
},
resolve: {
extensions: ['.mjs', '.js', '.ts', '.vue', '.json', '.scss'],
alias: {
'@': resolve(dirname(fileURLToPath(import.meta.url)), 'src')
}
},
base: './',
root: resolve('./src/renderer'),
publicDir: resolve('./src/renderer/public'),
clearScreen: false,
build: {
sourcemap: isDevEnv,
minify: !isDevEnv,
outDir: resolve('./dist'),
rollupOptions: {
input: {
main: resolve('index.html'),
translator: resolve('../translator/index.html')
}
}
},
plugins: [
Vue(),
VueJsx(),
// Docs: https://github.com/vuetifyjs/vuetify-loader
VuetifyPlugin({
autoImport: true
}),
// Docs: https://github.com/gxmari007/vite-plugin-eslint
// Docs: https://github.com/electron-vite/vite-plugin-electron
ElectronPlugin(electronPluginConfigs),
RendererPlugin()
]
}
})但是发现使用不了input属性,使用报错:Could not resolve entry module "../translator/index.html".
[vite-plugin-electron] Could not resolve entry module "../translator/index.html".
error during build:
RollupError: Could not resolve entry module "../translator/index.html".
at error (file:///D:/work/ChatDesk/YuKigal/node_modules/rollup/dist/es/shared/parseAst.js:337:30)
at ModuleLoader.loadEntryModule (file:///D:/work/ChatDesk/YuKigal/node_modules/rollup/dist/es/shared/node-entry.js:18021:20)
at async Promise.all (index 1)
electron版本:28.2.1 "vite-plugin-electron": "^0.28.7",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant