feat: build
This commit is contained in:
parent
6ae42923f7
commit
64af6c8247
|
@ -6,6 +6,7 @@ yarn-debug.log*
|
||||||
yarn-error.log*
|
yarn-error.log*
|
||||||
pnpm-debug.log*
|
pnpm-debug.log*
|
||||||
lerna-debug.log*
|
lerna-debug.log*
|
||||||
|
release
|
||||||
|
|
||||||
node_modules
|
node_modules
|
||||||
dist
|
dist
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -14,6 +14,7 @@
|
||||||
"@vitejs/plugin-basic-ssl": "^1.1.0",
|
"@vitejs/plugin-basic-ssl": "^1.1.0",
|
||||||
"@vitejs/plugin-vue": "^5.0.4",
|
"@vitejs/plugin-vue": "^5.0.4",
|
||||||
"electron": "^29.2.0",
|
"electron": "^29.2.0",
|
||||||
|
"electron-builder": "^24.13.3",
|
||||||
"esbuild": "^0.20.2",
|
"esbuild": "^0.20.2",
|
||||||
"typescript": "^5.2.2",
|
"typescript": "^5.2.2",
|
||||||
"vite": "^5.2.0",
|
"vite": "^5.2.0",
|
||||||
|
|
|
@ -0,0 +1,74 @@
|
||||||
|
import path from 'path'
|
||||||
|
import fs from 'fs'
|
||||||
|
|
||||||
|
class BuildObj {
|
||||||
|
buildMain() {
|
||||||
|
import('esbuild').then(build => {
|
||||||
|
build.buildSync({
|
||||||
|
entryPoints: ['./src/main/mainEntry.ts'],
|
||||||
|
bundle: true,
|
||||||
|
platform: "node",
|
||||||
|
minify: true,
|
||||||
|
outfile: './dist/mainEntry.js',
|
||||||
|
external: ['electron']
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
preparePackageJson() {
|
||||||
|
const pkgJsonPath = path.join(process.cwd(), 'package.json')
|
||||||
|
const localPkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf-8'))
|
||||||
|
const electronConfig = localPkgJson.devDependencies.electron.replace("^", "")
|
||||||
|
localPkgJson.main = "mainEntry.js"
|
||||||
|
delete localPkgJson.scripts
|
||||||
|
delete localPkgJson.devDependencies
|
||||||
|
localPkgJson.devDependencies = { electron: electronConfig }
|
||||||
|
const tarJsonPath = path.join(process.cwd(), "dist", "package.json")
|
||||||
|
fs.writeFileSync(tarJsonPath, JSON.stringify(localPkgJson))
|
||||||
|
fs.mkdirSync(path.join(process.cwd(), "dist/node_modules"))
|
||||||
|
}
|
||||||
|
|
||||||
|
buildInstaller() {
|
||||||
|
const options = {
|
||||||
|
config: {
|
||||||
|
directories: {
|
||||||
|
output: path.join(process.cwd(), "release"),
|
||||||
|
app: path.join(process.cwd(), 'dist')
|
||||||
|
},
|
||||||
|
files: ["**"],
|
||||||
|
extends: null,
|
||||||
|
productName: "JueJin",
|
||||||
|
appId: "com.juejin.desktop",
|
||||||
|
asar: true,
|
||||||
|
nsis: {
|
||||||
|
oneClick: true,
|
||||||
|
perMachine: true,
|
||||||
|
allowToChangeInstallationDirectory: false,
|
||||||
|
createDesktopShortcut: true,
|
||||||
|
createStartMenuShortcut: true,
|
||||||
|
shortcutName: "jujinDesktop"
|
||||||
|
},
|
||||||
|
// publish: [
|
||||||
|
// {provider: "generic", url: "http://localhost:5500"}
|
||||||
|
// ]
|
||||||
|
},
|
||||||
|
project: process.cwd()
|
||||||
|
}
|
||||||
|
return import('electron-builder').then(builder => {
|
||||||
|
builder.build(options)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const buildPlugin = () => {
|
||||||
|
return {
|
||||||
|
name: "build-plugin",
|
||||||
|
closeBundle: () => {
|
||||||
|
console.log('')
|
||||||
|
const buildObj = new BuildObj()
|
||||||
|
buildObj.buildMain()
|
||||||
|
buildObj.preparePackageJson()
|
||||||
|
buildObj.buildInstaller()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
1382
pnpm-lock.yaml
1382
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,14 @@
|
||||||
|
import { protocol } from 'electron'
|
||||||
|
// import fs from 'fs'
|
||||||
|
// import path from 'path'
|
||||||
|
|
||||||
|
const schemeConfig = {
|
||||||
|
standard: true,
|
||||||
|
supportFetchAPI: true,
|
||||||
|
bypassCSP: true,
|
||||||
|
corsEnabled: true,
|
||||||
|
stream: true
|
||||||
|
}
|
||||||
|
protocol.registerSchemesAsPrivileged([
|
||||||
|
{scheme: "app", privileges: schemeConfig}
|
||||||
|
])
|
|
@ -1,11 +1,12 @@
|
||||||
import { defineConfig } from 'vite'
|
import { defineConfig } from 'vite'
|
||||||
import vue from '@vitejs/plugin-vue'
|
import vue from '@vitejs/plugin-vue'
|
||||||
import { devPlugin, getReplacer } from './plugins/devPlugin'
|
import { devPlugin, getReplacer } from './plugins/devPlugin'
|
||||||
|
import { buildPlugin } from './plugins/buildPlugin'
|
||||||
import optimizer from 'vite-plugin-optimizer'
|
import optimizer from 'vite-plugin-optimizer'
|
||||||
|
|
||||||
// https://vitejs.dev/config/
|
// https://vitejs.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [optimizer(getReplacer()), devPlugin(), vue()],
|
plugins: [buildPlugin(), optimizer(getReplacer()), devPlugin(), vue()],
|
||||||
server: {
|
server: {
|
||||||
host: '127.0.0.1'
|
host: '127.0.0.1'
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue