-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbundle.js
120 lines (108 loc) · 2.57 KB
/
bundle.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
112
113
114
115
116
117
118
119
const webpack = require('webpack');
const less = require('less');
const fs = require('fs');
const path = require('path');
const packager = require('electron-packager');
//const webpackConfig = require('./webpack.config.js');
var mode = process.argv[2];
var build = process.argv[3] === 'build';
if (mode !== 'development' && mode !== 'production') {
console.log('Mode is not defined!');
return;
}
var webpackConfig = {
mode: mode,
entry: './app/src/app.js',
output: {
path: path.resolve(__dirname, 'app/dist'),
filename: 'bundle.js'
},
node: {
// neccessary for ffprobe-static
__dirname: true
},
resolve: {
alias: {
vue: 'vue/dist/vue.esm.js'
}
},
target: 'electron-renderer',
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.vue$/,
loader: 'vue-loader'
}
]
},
plugins: [
new webpack.DefinePlugin({
IS_DEV: JSON.stringify(mode === 'development'),
IS_BUILD: JSON.stringify(build)
})
]
}
function bundle_js() {
return new Promise((resolve, reject) => {
webpack(webpackConfig, (err, stats) => {
if (err) {
reject(err);
return;
}
console.log(stats.toString({ colors: true }));
resolve();
});
});
}
function bundle_css() {
const LESS_OPTIONS = { paths: [ './app/src/less/' ], compress: mode === 'production' };
return new Promise((resolve, reject) => {
// bundles less files into a single bundled css file
fs.readFile('./app/src/less/main.less', (err, data) => {
if (err) {
reject(err);
return;
}
less.render(data.toString(), LESS_OPTIONS, (err, output) => {
if (err) {
reject(err);
return;
}
fs.writeFileSync('./app/dist/bundle.css', output.css);
console.log('css successfully bundled.');
resolve();
});
});
});
}
function build_app(platform, arch) {
packager({
platform: platform,
arch: arch,
dir: './',
out: 'build/',
overwrite: true,
//TODO: use icon.icns for macOS
icon: path.join(__dirname, 'app/images/icon.ico')
}).then(appPaths => {
console.log('appPaths', appPaths);
var ffprobe_name = platform === 'win32' ? 'ffprobe.exe' : 'ffprobe';
var module_path = path.join(__dirname, 'node_modules/ffprobe-static/bin/', platform, arch, ffprobe_name);
var rel_path = path.relative(path.join(__dirname, appPaths[0]), module_path)
fs.symlinkSync(rel_path, path.join(appPaths[0], ffprobe_name));
}).catch(err => {
console.log(err);
});
}
Promise.all([bundle_css(), bundle_js()]).then(() => {
if (build) {
build_app('linux', 'x64');
}
}).catch(err => {
console.log(err);
});