-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
74 lines (61 loc) · 2.01 KB
/
build.js
File metadata and controls
74 lines (61 loc) · 2.01 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
const webpack = require('webpack');
const path = require('path');
const fs = require('fs');
// Import des configurations individuelles
const scriptsDev = require('./webpack/webpack.dev.js');
const scriptsMin = require('./webpack/webpack.prod.js');
const styles = require('./webpack/webpack.styles.js');
// Fonction pour exécuter une config Webpack
function runWebpack(config) {
return new Promise((resolve, reject) => {
webpack(config, (err, stats) => {
if (err || stats.hasErrors()) {
console.error(stats?.toString({ colors: true }));
return reject(err || new Error('Webpack error'));
}
console.log(stats.toString({ colors: true }));
resolve();
});
});
}
// Fonction pour fusionner les manifests partiels
function mergeManifests() {
const distPath = path.resolve(__dirname, 'dist');
const manifestFiles = [
'manifest-partial-scripts-dev.json',
'manifest-partial-scripts-min.json',
'manifest-partial-styles.json',
];
const finalManifest = {};
manifestFiles.forEach(file => {
const filePath = path.join(distPath, file);
if (fs.existsSync(filePath)) {
const content = JSON.parse(fs.readFileSync(filePath, 'utf8'));
Object.assign(finalManifest, content);
fs.unlinkSync(filePath); // Nettoyage des fichiers partiels
}
});
fs.writeFileSync(
path.join(distPath, 'manifest.json'),
JSON.stringify(finalManifest, null, 2)
);
console.log('✅ Manifest merged successfully.');
}
// Exécution séquentielle
async function buildAll() {
try {
console.log('🔨 Compilation JS (non minifié)…');
await runWebpack(scriptsDev);
console.log('🔨 Compilation JS (minifié)…');
await runWebpack(scriptsMin);
console.log('🎨 Compilation CSS…');
await runWebpack(styles);
console.log('🧩 Fusion des manifests…');
mergeManifests();
console.log('✅ Build complet terminé avec succès !');
} catch (error) {
console.error('❌ Build échoué :', error);
process.exit(1);
}
}
buildAll();