-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathbuild.js
More file actions
executable file
·75 lines (61 loc) · 2.12 KB
/
build.js
File metadata and controls
executable file
·75 lines (61 loc) · 2.12 KB
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
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
// Terser für Minification
let terser;
try {
terser = require('terser');
} catch (e) {
console.log('📦 Installiere Terser...');
require('child_process').execSync('npm install terser --no-save', { stdio: 'inherit' });
terser = require('terser');
}
const sourceFile = path.join(__dirname, 'assets', 'mblock.js');
const targetFile = path.join(__dirname, 'assets', 'mblock.min.js');
console.log('🔧 MBlock Build Script gestartet...');
console.log('📄 Source:', sourceFile);
console.log('📄 Target:', targetFile);
if (!fs.existsSync(sourceFile)) {
console.error('❌ Source-Datei nicht gefunden:', sourceFile);
process.exit(1);
}
const sourceCode = fs.readFileSync(sourceFile, 'utf8');
console.log('✅ Source-Code gelesen:', sourceCode.length, 'Zeichen');
const options = {
compress: {
dead_code: true,
drop_console: false,
passes: 2
},
mangle: {
reserved: ['$', 'jQuery', 'MBlockClipboard', 'openLinkMap', 'deleteREXLink']
},
format: {
comments: false
},
sourceMap: true
};
console.log('⚙️ Minifiziere Code...');
terser.minify(sourceCode, options).then(result => {
if (result.error) {
console.error('❌ Minification Fehler:', result.error);
process.exit(1);
}
fs.writeFileSync(targetFile, result.code);
console.log('✅ Minifizierte Datei erstellt:', targetFile);
if (result.map) {
fs.writeFileSync(targetFile + '.map', result.map);
console.log('🗺️ Source Map erstellt');
}
const originalSize = sourceCode.length;
const minifiedSize = result.code.length;
const savings = ((originalSize - minifiedSize) / originalSize * 100).toFixed(1);
console.log('\n📈 Statistiken:');
console.log(' Original:', originalSize, 'Zeichen');
console.log(' Minifiziert:', minifiedSize, 'Zeichen');
console.log(' Ersparnis:', savings + '%');
console.log('\n🎉 Build erfolgreich!');
}).catch(error => {
console.error('❌ Build Fehler:', error);
process.exit(1);
});