mirror of
https://github.com/electron-vite/electron-vite-vue
synced 2025-01-19 11:56:36 +08:00
!!! ensure cwd crrect
This commit is contained in:
parent
030b7a5f3f
commit
f6f363364d
@ -1,7 +1,8 @@
|
||||
import { builtinModules } from 'module'
|
||||
import { sep } from 'path'
|
||||
import { sep, join } from 'path'
|
||||
import { get } from 'http'
|
||||
import { green } from 'chalk'
|
||||
import { Plugin } from 'rollup'
|
||||
|
||||
/** 轮询监听 vite 启动 */
|
||||
export function waitOn(arg0: { port: string | number; interval?: number; }) {
|
||||
@ -41,5 +42,22 @@ export function cjs2esm() {
|
||||
}
|
||||
}
|
||||
|
||||
/** node.js 内置模块 */
|
||||
/** ensure cwd crrect */
|
||||
export function ensureCwdCrrect(filename: string): Plugin {
|
||||
return {
|
||||
name: 'cxmh:ensure-cwd-crrect',
|
||||
transform(code, id) {
|
||||
if (id === filename) {
|
||||
return `
|
||||
// !!! ensure cwd crrect
|
||||
process.chdir(__dirname)
|
||||
|
||||
${code}
|
||||
`
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/** node.js builtins module */
|
||||
export const builtins = () => builtinModules.filter(x => !/^_|^(internal|v8|node-inspect)\/|\//.test(x))
|
||||
|
@ -1,11 +1,18 @@
|
||||
/**
|
||||
* !!! ensure cwd crrect
|
||||
*/
|
||||
process.chdir(__dirname)
|
||||
|
||||
import { createApp } from 'vue'
|
||||
import App from './App.vue'
|
||||
import fs = require('fs')
|
||||
import { ipcRenderer } from 'electron'
|
||||
// import Store from 'electron-store'
|
||||
import Store from 'electron-store'
|
||||
import './index.css'
|
||||
|
||||
console.log('fs', fs)
|
||||
console.log('ipcRenderer:', ipcRenderer)
|
||||
// console.log('electron-store', new Store({ name: 'electron-vue' }))
|
||||
console.log('electron-store', new Store({ name: 'electron-vue' }))
|
||||
|
||||
createApp(App)
|
||||
.mount('#app')
|
||||
|
@ -3,13 +3,15 @@ require('dotenv').config({ path: join(__dirname, '.env') })
|
||||
import { defineConfig } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
import { join } from 'path'
|
||||
import typescript from '@rollup/plugin-typescript'
|
||||
import { builtins } from './script/utils'
|
||||
// import typescript from '@rollup/plugin-typescript'
|
||||
import { builtins, ensureCwdCrrect } from './script/utils'
|
||||
|
||||
const root = join(__dirname, 'src/render')
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [vue()],
|
||||
root: join(__dirname, 'src/render'),
|
||||
root,
|
||||
base: './', // index.html 中静态资源加载位置
|
||||
server: {
|
||||
port: +process.env.PORT,
|
||||
@ -24,18 +26,13 @@ export default defineConfig({
|
||||
outDir: join(__dirname, 'dist/render'),
|
||||
emptyOutDir: true,
|
||||
minify: false,
|
||||
commonjsOptions: {
|
||||
dynamicRequireTargets: [
|
||||
join(__dirname, 'package.json'),
|
||||
],
|
||||
},
|
||||
commonjsOptions: {},
|
||||
assetsDir: '', // 相对路径 加载问题
|
||||
sourcemap: true,
|
||||
rollupOptions: {
|
||||
plugins: [
|
||||
// typescript({
|
||||
// module: 'ESNext',
|
||||
// }),
|
||||
// typescript({ module: 'ESNext' }),
|
||||
// ensureCwdCrrect(join(root, 'main.ts')),
|
||||
],
|
||||
external: [
|
||||
...builtins(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user