mirror of
https://github.com/electron-vite/electron-vite-vue
synced 2025-01-31 20:16:36 +08:00
rollup 打包问题修复
This commit is contained in:
parent
f65f27e6d5
commit
5c6d386b15
@ -11,7 +11,7 @@
|
|||||||
"dev:ele": "node script/build --env=development --watch",
|
"dev:ele": "node script/build --env=development --watch",
|
||||||
"build:vue": "vite build",
|
"build:vue": "vite build",
|
||||||
"build:ele": "node script/build --env=production",
|
"build:ele": "node script/build --env=production",
|
||||||
"build": "npm run build:vue && npm run build:ele && electron-builder"
|
"build": "rm -rf dist && npm run build:vue && npm run build:ele && electron-builder"
|
||||||
},
|
},
|
||||||
"build": {
|
"build": {
|
||||||
"appId": "308487730@qq.com",
|
"appId": "308487730@qq.com",
|
||||||
@ -63,8 +63,8 @@
|
|||||||
"minimist": "^1.2.5",
|
"minimist": "^1.2.5",
|
||||||
"ora": "^5.0.0",
|
"ora": "^5.0.0",
|
||||||
"rollup-plugin-esbuild": "^2.4.2",
|
"rollup-plugin-esbuild": "^2.4.2",
|
||||||
"typescript": "^3.9.7",
|
"typescript": "^4.0.3",
|
||||||
"vite": "^1.0.0-rc.1",
|
"vite": "^1.0.0-rc.4",
|
||||||
"wait-on": "^5.2.0"
|
"wait-on": "^5.2.0"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
|
@ -59,7 +59,6 @@ module.exports = (env = 'production') => {
|
|||||||
'https',
|
'https',
|
||||||
'path',
|
'path',
|
||||||
'electron',
|
'electron',
|
||||||
'electron-is-dev',
|
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ function createWin() {
|
|||||||
|
|
||||||
const URL = is_dev
|
const URL = is_dev
|
||||||
? `http://localhost:${process.env.PORT}` // vite 启动的服务器地址
|
? `http://localhost:${process.env.PORT}` // vite 启动的服务器地址
|
||||||
: `file://${join(__dirname, '../../dist/render/index.html')}` // vite 构建后的静态文件地址
|
: `file://${join(__dirname, '../render/index.html')}` // vite 构建后的静态文件地址
|
||||||
|
|
||||||
win.loadURL(URL)
|
win.loadURL(URL)
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
import { createApp } from 'vue'
|
import { createApp } from 'vue'
|
||||||
import App from './App.vue'
|
import App from './App.vue'
|
||||||
import './index.css'
|
|
||||||
// vite 会编译 import 的形式;所以 electron 及 node.js 内置模块用 require 形式
|
// vite 会编译 import 的形式;所以 electron 及 node.js 内置模块用 require 形式
|
||||||
const { ipcRenderer } = require('electron')
|
const { ipcRenderer } = require('electron')
|
||||||
const Store = require('electron-store')
|
import store from '/utils/store'
|
||||||
|
|
||||||
const store = new Store
|
import './index.css'
|
||||||
|
|
||||||
console.log('ipcRenderer:', ipcRenderer)
|
console.log('ipcRenderer:', ipcRenderer)
|
||||||
console.log('Store', store)
|
console.log('Store', store)
|
||||||
|
3
src/render/utils/store.ts
Normal file
3
src/render/utils/store.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
/*@replace = import Store from 'electron-store'*/const Store = require('electron-store')
|
||||||
|
|
||||||
|
export default new Store
|
@ -10,8 +10,11 @@
|
|||||||
"baseUrl": "./",
|
"baseUrl": "./",
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"paths": {
|
"paths": {
|
||||||
"@/*": ["src/render/*"],
|
"/assets/*": ["src/render/assets/*"],
|
||||||
"root/*": ["/*"]
|
"/components/*": ["src/render/components/*"],
|
||||||
|
"/lib/*": ["src/render/lib/*"],
|
||||||
|
"/utils/*": ["src/render/utils/*"],
|
||||||
|
"/views/*": ["src/render/views/*"]
|
||||||
},
|
},
|
||||||
"allowSyntheticDefaultImports": true
|
"allowSyntheticDefaultImports": true
|
||||||
},
|
},
|
||||||
|
@ -15,12 +15,52 @@ const config: UserConfig = {
|
|||||||
outDir: join(__dirname, 'dist/render'),
|
outDir: join(__dirname, 'dist/render'),
|
||||||
alias: {
|
alias: {
|
||||||
// 别名必须以 / 开头、结尾
|
// 别名必须以 / 开头、结尾
|
||||||
'/@/': root,
|
// '/@/': root, -- vite 内部在用,这里不能用了
|
||||||
|
// '/root/': __dirname, -- vite 内部在用,这里不能用了
|
||||||
|
'/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: {
|
optimizeDeps: {
|
||||||
// 这里不加也没事,用 require 的形式就能避开 import 被编译成 /@modules/fs?import
|
// 这里不加也没事,用 require 的形式就能避开 import 被编译成 /@modules/fs?import
|
||||||
// allowNodeBuiltins: ['electron-is-dev', 'electron-store', 'electron']
|
// allowNodeBuiltins: ['electron-is-dev', 'electron-store', 'electron']
|
||||||
},
|
},
|
||||||
|
rollupInputOptions: {
|
||||||
|
external: [
|
||||||
|
'crypto',
|
||||||
|
'assert',
|
||||||
|
'fs',
|
||||||
|
'util',
|
||||||
|
'os',
|
||||||
|
'events',
|
||||||
|
'child_process',
|
||||||
|
'http',
|
||||||
|
'https',
|
||||||
|
'path',
|
||||||
|
'electron',
|
||||||
|
],
|
||||||
|
plugins: [
|
||||||
|
{
|
||||||
|
name: '@rollup/plugin-replace-electron-store',
|
||||||
|
transform(code, id) {
|
||||||
|
// const Store = require('electron-store')
|
||||||
|
const electronStoreReg = /(const|let|var)[\n\s]+(\w+)[\n\s]*=[\n\s]*require\(["|']electron-store["|']\)/g
|
||||||
|
const res = code.match(electronStoreReg)
|
||||||
|
/*@replace = import Store from 'electron-store'*/
|
||||||
|
// const replaceStore = /\/\*\s*@replace\s*=\s*([\S\s]+)\s*\*\//g
|
||||||
|
if (res) {
|
||||||
|
code = code.replace(electronStoreReg, `import $2 from 'electron-store'`)
|
||||||
|
}
|
||||||
|
return code
|
||||||
|
},
|
||||||
|
}
|
||||||
|
],
|
||||||
|
},
|
||||||
|
rollupOutputOptions: {
|
||||||
|
format: 'commonjs',
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
export default config
|
export default config
|
||||||
|
Loading…
x
Reference in New Issue
Block a user