-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
97 lines (86 loc) · 2.44 KB
/
webpack.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
94
95
96
97
const path = require("path");
const fs = require("fs");
const archiver = require("archiver");
const extSourcePath = path.resolve(__dirname, "src/extension");
const distPath = path.resolve(__dirname, "dist/atrica-extension");
const xpiFilePath = path.resolve(__dirname, "dist/atrica-extension.xpi");
class AtricaSetup {
apply(compiler) {
compiler.hooks.done.tapPromise("Setup atrica", async () => {
try {
console.log("Copying events files");
const events = ["document_start", "document_end", "document_idle"];
await Promise.all(
events.map(async event => {
await fs.promises.copyFile(
path.resolve(extSourcePath, `${event}.js`),
path.resolve(distPath, `${event}.js`)
);
})
);
console.log("Copying manifest.json");
// Loading manifest
let manifestJson = await fs.promises.readFile(
path.join(extSourcePath, "manifest.json"),
{ encoding: "utf8" }
);
// Chaging version
let manifest = JSON.parse(manifestJson);
let ms = new Date().getTime().toString();
let dec = ms.slice.bind(ms);
let version = `${dec(0, 4)}.1${dec(4, 7)}.1${dec(7, 10)}`;
manifest.version = version;
//Manifest for chrome
await fs.promises.writeFile(
path.join(distPath, "manifest.json"),
JSON.stringify(manifest, null, 3)
);
//Manifest for firefox
manifest.permissions = manifest.permissions.filter(
p => !["debugger"].includes(p)
);
console.log("Generating XPI file...");
let output = fs.createWriteStream(xpiFilePath);
let archive = archiver("zip", { zlib: { level: 9 } });
archive.pipe(output);
archive.glob("!(manifest.json)", { cwd: distPath });
archive.append(JSON.stringify(manifest, null, 3), {
name: "manifest.json"
});
archive.finalize();
return await new Promise((resolve, reject) => {
archive.on("finish", () => {
console.log("Done!");
resolve();
});
archive.on("error", error => {
console.log("Error");
reject(error);
});
});
} catch (error) {
console.log(error);
}
});
}
}
module.exports = (env, argv) => ({
watch: argv.mode === "development",
entry: {
background: path.resolve(extSourcePath, "background.js")
},
output: {
filename: "[name].js",
path: distPath
},
devtool: "source-map",
optimization: {
minimize: false
},
plugins: [new AtricaSetup()],
performance: {
hints: false,
maxEntrypointSize: 512000,
maxAssetSize: 512000
}
});