forked from sienori/simple-translate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.utils.js
100 lines (92 loc) · 2.82 KB
/
webpack.utils.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
/* Copyright (c) 2018 Kamil Mikosz
* Copyright (c) 2019 Sienori
* Released under the MIT license.
* see https://opensource.org/licenses/MIT */
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const ZipPlugin = require("zip-webpack-plugin");
const path = require("path");
const getHTMLPlugins = (browserDir, outputDir = "dev", sourceDir = "src") => [
new HtmlWebpackPlugin({
title: "Popup",
filename: path.resolve(__dirname, `${outputDir}/${browserDir}/popup/index.html`),
template: `${sourceDir}/popup/index.html`,
chunks: ["popup"]
}),
new HtmlWebpackPlugin({
title: "Options",
filename: path.resolve(__dirname, `${outputDir}/${browserDir}/options/index.html`),
template: `${sourceDir}/options/index.html`,
chunks: ["options"]
})
];
const getOutput = (browserDir, outputDir = "dev") => {
return {
path: path.resolve(__dirname, `${outputDir}/${browserDir}`),
filename: "[name]/[name].js"
};
};
const getEntry = (sourceDir = "src") => {
return {
popup: path.resolve(__dirname, `${sourceDir}/popup/index.js`),
options: path.resolve(__dirname, `${sourceDir}/options/index.js`),
content: path.resolve(__dirname, `${sourceDir}/content/index.js`),
background: path.resolve(__dirname, `${sourceDir}/background/background.js`)
};
};
const getCopyPlugins = (browserDir, outputDir = "dev", sourceDir = "src") => [
new CopyWebpackPlugin([
{
from: `${sourceDir}/icons`,
to: path.resolve(__dirname, `${outputDir}/${browserDir}/icons`)
},
{
from: `${sourceDir}/_locales`,
to: path.resolve(__dirname, `${outputDir}/${browserDir}/_locales`)
},
{
from: `${sourceDir}/manifest-chrome.json`,
to: path.resolve(__dirname, `${outputDir}/${browserDir}/manifest.json`)
}
])
];
const getFirefoxCopyPlugins = (browserDir, outputDir = "dev", sourceDir = "src") => [
new CopyWebpackPlugin([
{
from: `${sourceDir}/icons`,
to: path.resolve(__dirname, `${outputDir}/${browserDir}/icons`)
},
{
from: `${sourceDir}/_locales`,
to: path.resolve(__dirname, `${outputDir}/${browserDir}/_locales`)
},
{
from: `${sourceDir}/manifest-firefox.json`,
to: path.resolve(__dirname, `${outputDir}/${browserDir}/manifest.json`)
}
])
];
const getZipPlugin = (browserDir, outputDir = "dist", exclude = "") =>
new ZipPlugin({
path: path.resolve(__dirname, `${outputDir}`),
filename: browserDir,
extension: "zip",
fileOptions: {
mtime: new Date(),
mode: 0o100664,
compress: true,
forceZip64Format: false
},
zipOptions: {
forceZip64Format: false
},
exclude: exclude
});
module.exports = {
getHTMLPlugins,
getOutput,
getCopyPlugins,
getFirefoxCopyPlugins,
getZipPlugin,
getEntry
};