This repository was archived by the owner on Feb 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebpack_plugins.js
More file actions
47 lines (44 loc) · 1.73 KB
/
webpack_plugins.js
File metadata and controls
47 lines (44 loc) · 1.73 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
const fs = require("fs");
const path = require("path");
const vendors = require("./vendors.json");
const packageJSON = require("./package.json");
/**
* génère un manifest au format json
* @param {object} options - configuration du plugin
* @param {Array.<string>} options.extensionToIgnore - tableau des extension à ne pas inclure dans le manifest
* @param {string} [options.filePath] - emplacement du manifest
* @param {string} [options.fileName] - nom du manifest
*/
function manifestPlugin (options = {extensionToIgnore: ["map.js"]}) {
return function () {
this.plugin("done", function (stats) {
const ignore = new RegExp(`${options.extensionToIgnore.join("|")}$`);
let manifest = {};
debugger;
stats.compilation.chunks.forEach((chunk) => {
chunk.files.forEach((file) => {
let extension = file.split(".").pop() || "";
if (options.extensionToIgnore.length > 0 && !ignore.test(file)) {
manifest[`${chunk.name}.${extension}`] = file;
}
});
});
fs.writeFileSync(path.resolve(options.filePath || stats.compilation.chunkTemplate.outputOptions.path, options.fileName || "manifest.json"), JSON.stringify(manifest));
});
}
}
/**
* renvoie les dépendances à mettre dans le bundle vendors
* Il est possible de forcer l'exclusion ou inclusion de dépendance dans le fichier vendors.json
* @return {Array.<string>}
*/
function getVendors () {
const dependencies = Object.keys(packageJSON.dependencies)
.filter(dependency => (vendors.exclude||[]).indexOf(dependency) === -1);
return dependencies.concat((vendors.include||[])
.filter(dependency => dependencies.indexOf(dependency) === -1));
}
module.exports = {
manifestPlugin,
getVendors
};