This repository has been archived by the owner on Nov 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
vue.config.js
101 lines (93 loc) · 2.17 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
const {
appName,
} = require('./src/config/index');
const {
isExist,
pathJoin,
} = require('./src/utils/node');
module.exports = {
pages: createPages('./src/windows'),
pluginOptions: {
electronBuilder: {
mainProcessFile: './src/background/index.js',
mainProcessWatch: ['./src/background/**'],
nodeIntegration: true,
builderOptions: {
npmRebuild: false,
productName: appName,
appId: 'com.jar.starter.box',
win: {
icon: 'public/logos/index.ico',
target: 'nsis',
},
},
},
},
chainWebpack(config) {
// set svg-sprite-loader
config.module
.rule('svg')
.exclude.add(pathJoin('src/icons'))
.end();
config.module
.rule('icons')
.test(/\.svg$/)
.include.add(pathJoin('src/icons'))
.end()
.use('svg-sprite-loader')
.loader('svg-sprite-loader')
.options({
symbolId: 'svg-[name]',
})
.end();
},
};
function createPages(dirPath) {
const isCanDir = isExist(dirPath);
let files = [];
if (isCanDir) {
const klawSync = require('klaw-sync');
// @ts-ignore
files = klawSync(dirPath, {
nodir: true,
traverseAll: true,
filter({
path,
}) {
return !!path.match(/main\.js/);
},
});
}
// console.log('files', files);
const windowsPathLength = pathJoin(dirPath).length;
const regExp = process.platform !== 'win32' ? /\//g : /\\/g;
// 入口页面
const initPage = {
index: {
entry: './src/main.js',
template: './public/index.html',
filename: 'index.html',
title: appName,
},
};
const pages = files.reduce((obj, {
path,
}) => {
const filename = path
.substring(windowsPathLength + 1)
.replace(regExp, '_')
.replace(/_main/, '')
.replace(/\.js$/, '.html');
console.log('filename', filename);
const pageName = filename.substring(0, filename.lastIndexOf('.'));
console.log('pageName', pageName);
obj[pageName] = {
entry: path,
template: './public/index.html',
filename,
title: appName,
};
return obj;
}, initPage);
return pages;
}