forked from undergroundwires/privacy.sexy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvue.config.js
93 lines (86 loc) · 3.22 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
const { resolve } = require('path');
const { defineConfig } = require('@vue/cli-service');
const packageJson = require('./package.json');
const tsconfigJson = require('./tsconfig.json');
loadVueAppRuntimeVariables();
module.exports = defineConfig({
transpileDependencies: true,
chainWebpack: (config) => {
changeAppEntryPoint('./src/presentation/main.ts', config);
addWebpackRule('yaml', /\.ya?ml$/, 'js-yaml-loader', config);
},
configureWebpack: {
resolve: {
alias: {
...getAliasesFromTsConfig(),
},
fallback: {
/* Tell webpack to ignore polyfilling them because Node core modules are never used
for browser code but only for desktop where Electron supports them. */
...ignorePolyfills('os', 'child_process', 'fs', 'path'),
},
},
// Fix compilation failing on macOS when running unit/integration tests
externals: ['fsevents'],
},
pluginOptions: {
// https://nklayman.github.io/vue-cli-plugin-electron-builder/guide/guide.html#native-modules
electronBuilder: {
mainProcessFile: './src/presentation/electron/main.ts', // https://nklayman.github.io/vue-cli-plugin-electron-builder/guide/configuration.html#webpack-configuration
nodeIntegration: true, // required to reach Node.js APIs for environment specific logic
// https://www.electron.build/configuration/configuration
builderOptions: {
publish: [{
// https://www.electron.build/configuration/publish#githuboptions
// https://nklayman.github.io/vue-cli-plugin-electron-builder/guide/recipes.html#enable-publishing-to-github
provider: 'github',
vPrefixedTagName: false, // default: true
releaseType: 'release', // or "draft" (default), "prerelease"
}],
mac: { // https://www.electron.build/configuration/mac
target: 'dmg',
},
win: { // https://www.electron.build/configuration/win
target: 'nsis',
},
linux: { // https://www.electron.build/configuration/linux
target: 'AppImage',
},
},
},
},
});
function addWebpackRule(name, test, loader, config) {
config.module
.rule(name)
.test(test)
.use(loader)
.loader(loader)
.end();
}
function changeAppEntryPoint(entryPath, config) {
config.entry('app').clear().add(entryPath).end();
}
function loadVueAppRuntimeVariables() {
process.env.VUE_APP_VERSION = packageJson.version;
process.env.VUE_APP_NAME = packageJson.name;
process.env.VUE_APP_REPOSITORY_URL = packageJson.repository.url;
process.env.VUE_APP_HOMEPAGE_URL = packageJson.homepage;
}
function ignorePolyfills(...moduleNames) {
return moduleNames.reduce((obj, module) => {
obj[module] = false;
return obj;
}, {});
}
function getAliasesFromTsConfig() {
const { paths } = tsconfigJson.compilerOptions;
return Object.keys(paths).reduce((aliases, pathName) => {
const pathFolder = paths[pathName][0];
const aliasFolder = pathFolder.substring(0, pathFolder.length - 1); // trim * from end
const aliasName = pathName.substring(0, pathName.length - 2); // trim /* from end
const aliasPath = resolve(__dirname, aliasFolder);
aliases[aliasName] = aliasPath;
return aliases;
}, {});
}