-
Notifications
You must be signed in to change notification settings - Fork 0
/
vue.config.js
111 lines (104 loc) · 3.9 KB
/
vue.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* eslint-disable quote-props */
const { defineConfig } = require('@vue/cli-service')
const webpack = require('webpack');
const path = require('path');
const process = require("process")
const os = require('os');
const BytenodeWebpackPlugin = require('./src/plugins/electron-bytenode-webpack-plugin')
// 生成从minNum到maxNum的随机数
const randomRange = function (minNum, maxNum) {
switch (arguments.length) {
case 1:
return parseInt(Math.random() * minNum + 1, 10);
case 2:
return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10);
default:
return 0;
}
}
const generateBuildNumber = () => {
const mapTable = "0123456789abcdef"
let res = ""
for (let i = 0; i < 20; i++) {
res += mapTable[randomRange(0, mapTable.length - 1)]
}
return res;
}
function prettyBytes(bytes, decimals) {
if (isNaN(parseInt(bytes))) return 'unknown'
if (bytes === 0) return '0 Bytes'
const k = 1024
const dm = decimals <= 0 ? 0 : decimals || 2
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
const i = Math.floor(Math.log(bytes) / Math.log(k))
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]
}
console.log(JSON.stringify(os.cpus(), undefined, 4))
module.exports = defineConfig({
transpileDependencies: true,
productionSourceMap: false,
pluginOptions: {
electronBuilder: {
disableMainProcessTypescript: true,
mainProcessTypeChecking: false,
nodeIntegration: true,
// Use this to change the entry point of your app's render process. default src/[main|index].[js|ts]
builderOptions: {
productName: "gcrypt-隐域",
appId: "",
compression: "maximum",
// directories: {
// output: "build",
// },
// files: ["dist_electron/**/*"],
win: {
icon: "public/icons/icon.ico",
target: "nsis",
},
nsis: {
oneClick: false,
allowToChangeInstallationDirectory: true,
displayLanguageSelector: true,
},
},
externals: ['clipboard']
},
vuetify: {
// https://github.com/vuetifyjs/vuetify-loader/tree/next/packages/vuetify-loader
}
},
configureWebpack: (config) => {
// renderer使用node
config.externals = {
'electron': 'require("electron")',
'https': 'require("https")',
'http': 'require("http")',
'path': 'require("path")',
}
config.resolve = {
extensions: ['.js', '.vue', '.json', '.ts'],
alias: {
// 在 webpack 中设置代码中 @ 符号表示 src 这一层目录
'@': require("path").join(__dirname, './src/')
}
}
const totalMem = os.totalmem();
const freeMem = os.freemem();
config.plugins.push(new webpack.DefinePlugin({
COMPILE_DATE: JSON.stringify(new Date().toLocaleString()),
COMPILE_NUMBER: JSON.stringify(generateBuildNumber()),
COMPILE_PLATFORM: JSON.stringify(process.platform + ' ' + os.version() + ' ' + os.release()),
COMPILE_ENV: JSON.stringify(JSON.stringify(process.env, undefined, 4)),
COMPILE_CPU: JSON.stringify(JSON.stringify(os.cpus(), undefined, 4)),
COMPILE_MEM: JSON.stringify(`total: ${prettyBytes(totalMem)}, free: ${prettyBytes(freeMem)}`)
}))
config.plugins.push(new BytenodeWebpackPlugin())
},
chainWebpack: config => {
function resolvePath(...dir) {
return path.join(__dirname, ...dir)
}
config.resolve.alias
.set("@", resolvePath("src"))
}
})