mirror of
https://github.com/electron-vite/electron-vite-vue
synced 2025-01-19 11:56:36 +08:00
chore: Struct adjust
This commit is contained in:
parent
48d5a92e6d
commit
7b472f36c6
@ -1,3 +1,4 @@
|
||||
import { sep } from 'path'
|
||||
import { get } from 'http'
|
||||
import { green } from 'chalk'
|
||||
|
||||
@ -18,3 +19,23 @@ export function waitOn(arg0: { port: string | number; interval?: number; }) {
|
||||
}, interval)
|
||||
})
|
||||
}
|
||||
|
||||
/** cjs2esm */
|
||||
export function cjs2esm() {
|
||||
return {
|
||||
name: '@rollup/plugin-cjs2esm',
|
||||
transform(code: string, filename: string) {
|
||||
if (filename.includes(`${sep}node_modules${sep}`)) {
|
||||
return code
|
||||
}
|
||||
|
||||
const cjsRegexp = /(const|let|var)[\n\s]+(\w+)[\n\s]*=[\n\s]*require\(["|'](.+)["|']\)/g
|
||||
const res = code.match(cjsRegexp)
|
||||
if (res) {
|
||||
// const Store = require('electron-store') -> import Store from 'electron-store'
|
||||
code = code.replace(cjsRegexp, `import $2 from '$3'`)
|
||||
}
|
||||
return code
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,10 @@
|
||||
/**
|
||||
* electron 主文件
|
||||
*/
|
||||
require('dotenv').config({ path: join(__dirname, '../../.env') })
|
||||
|
||||
import { join } from 'path'
|
||||
import { app, BrowserWindow } from 'electron'
|
||||
import dotenv from 'dotenv'
|
||||
|
||||
dotenv.config({ path: join(__dirname, '../../.env') })
|
||||
|
||||
let win: BrowserWindow
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
// @ts-nocheck
|
||||
|
||||
/** docoment 加载完成 */
|
||||
function domReady(...args) {
|
||||
|
@ -2,12 +2,8 @@ import { createApp } from 'vue'
|
||||
import App from './App.vue'
|
||||
// vite 会编译 import 的形式;所以 electron 及 node.js 内置模块用 require 形式
|
||||
const { ipcRenderer } = require('electron')
|
||||
// import { store, isdev } from '/utils/index'
|
||||
|
||||
import './index.css'
|
||||
|
||||
console.log('ipcRenderer:', ipcRenderer)
|
||||
// console.log('Store', store)
|
||||
// console.log('electron is dev', isdev)
|
||||
|
||||
createApp(App as any).mount('#app').$nextTick(window.ClosePreloadLoading)
|
||||
createApp(App).mount('#app').$nextTick(window.ClosePreloadLoading)
|
||||
|
2
src/render/typings.d.ts
vendored
2
src/render/typings.d.ts
vendored
@ -7,5 +7,5 @@ declare module '*.jpg'
|
||||
|
||||
interface Window {
|
||||
/** 关闭预加载动画 */
|
||||
ClosePreloadLoading: () => void
|
||||
ClosePreloadLoading: () => void
|
||||
}
|
||||
|
@ -1,7 +0,0 @@
|
||||
import store from './store'
|
||||
const isdev = require('electron-is-dev')
|
||||
|
||||
export {
|
||||
store,
|
||||
isdev,
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
/*@replace = import Store from 'electron-store'*/const Store = require('electron-store')
|
||||
|
||||
export default new Store
|
@ -11,16 +11,12 @@
|
||||
"baseUrl": "./",
|
||||
"strict": true,
|
||||
"paths": {
|
||||
"/assets/*": ["src/render/assets/*"],
|
||||
"/components/*": ["src/render/components/*"],
|
||||
"/lib/*": ["src/render/lib/*"],
|
||||
"/utils/*": ["src/render/utils/*"],
|
||||
"/views/*": ["src/render/views/*"]
|
||||
"@/*": ["src/render/*"],
|
||||
"@root/*": ["./*"],
|
||||
},
|
||||
"allowSyntheticDefaultImports": true
|
||||
},
|
||||
"include": [
|
||||
"src/**/*",
|
||||
"typings/*.d.ts"
|
||||
"src"
|
||||
]
|
||||
}
|
||||
|
@ -1,71 +1,35 @@
|
||||
require('dotenv').config({ path: join(__dirname, '.env') })
|
||||
|
||||
import { defineConfig } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
import { join, sep } from 'path'
|
||||
import dotenv from 'dotenv'
|
||||
|
||||
dotenv.config({ path: join(__dirname, '.env') })
|
||||
const root = join(__dirname, 'src/render')
|
||||
import externals from 'rollup-plugin-node-externals'
|
||||
import { join } from 'path'
|
||||
import { cjs2esm } from './script/utils'
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [vue()],
|
||||
root,
|
||||
// base: './',
|
||||
root: join(__dirname, 'src/render'),
|
||||
server: {
|
||||
port: +process.env.PORT,
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': join(__dirname, 'src/render'),
|
||||
'@root': __dirname,
|
||||
'@assets': join(__dirname, 'src/render/assets'),
|
||||
'@components': join(__dirname, 'src/render/components'),
|
||||
'@lib': join(__dirname, 'src/render/lib'),
|
||||
'@utils': join(__dirname, 'src/render/utils'),
|
||||
'@views': join(__dirname, 'src/render/views'),
|
||||
},
|
||||
},
|
||||
optimizeDeps: {
|
||||
// 这里不加也没事,用 require 的形式就能避开 import 被编译成 /@modules/fs?import
|
||||
// allowNodeBuiltins: ['electron-is-dev', 'electron-store', 'electron']
|
||||
exclude: ['electron-store', 'electron']
|
||||
},
|
||||
build: {
|
||||
outDir: join(__dirname, 'dist/render'),
|
||||
rollupOptions: {
|
||||
output: {
|
||||
// format: 'commonjs',
|
||||
},
|
||||
external: [
|
||||
'crypto',
|
||||
'assert',
|
||||
'fs',
|
||||
'util',
|
||||
'os',
|
||||
'events',
|
||||
'child_process',
|
||||
'http',
|
||||
'https',
|
||||
'path',
|
||||
'electron',
|
||||
],
|
||||
external: ['electron'],
|
||||
plugins: [
|
||||
{
|
||||
name: '@rollup/plugin-cjs2esm',
|
||||
transform(code, filename) {
|
||||
if (filename.includes(`${sep}node_modules${sep}`)) {
|
||||
return code
|
||||
}
|
||||
|
||||
const cjsRegexp = /(const|let|var)[\n\s]+(\w+)[\n\s]*=[\n\s]*require\(["|'](.+)["|']\)/g
|
||||
const res = code.match(cjsRegexp)
|
||||
if (res) {
|
||||
// const Store = require('electron-store') -> import Store from 'electron-store'
|
||||
code = code.replace(cjsRegexp, `import $2 from '$3'`)
|
||||
}
|
||||
return code
|
||||
},
|
||||
}
|
||||
externals(),
|
||||
// cjs2esm(),
|
||||
],
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user