-
Notifications
You must be signed in to change notification settings - Fork 11
/
webpack.config.js
90 lines (87 loc) · 2.53 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
const path = require("path"),
CleanWebpackPlugin = require("clean-webpack-plugin").CleanWebpackPlugin,
CopyWebpackPlugin = require("copy-webpack-plugin"),
HtmlWebpackPlugin = require("html-webpack-plugin"),
ZipPlugin = require("zip-webpack-plugin");
const fs = require("fs");
const webpack = require("webpack");
module.exports = (env) => {
const mode = process.env.NODE_ENV || "production";
return {
mode,
devtool: mode === "development" ? "source-map" : false,
entry: {
ptt: path.resolve(__dirname, "src/ptt.js"),
background: path.resolve(__dirname, "src/background.js"),
options: path.resolve(__dirname, "src/options.js"),
},
output: {
filename: "[name].bundle.js",
path: path.resolve(__dirname, "dist"),
},
module: {
rules: [
{
test: /\.css$/i,
use: ["style-loader", "css-loader"],
},
{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: "babel-loader",
options: {
presets: [
[
"@babel/preset-env",
{
targets: {
chrome: "80",
},
},
],
],
},
},
},
],
},
plugins: [
new webpack.DefinePlugin({
__VERSION__: JSON.stringify(process.env.npm_package_version),
}),
new CleanWebpackPlugin(),
new CopyWebpackPlugin({
patterns: [
{ from: "src/icons", to: "icons" },
{
from: "src/manifest.json",
transform: function (content, path) {
return Buffer.from(
JSON.stringify({
version: JSON.parse(fs.readFileSync("./package.json"))
.version,
content_security_policy:
mode === "development"
? "script-src 'self' 'unsafe-eval'; object-src 'self'"
: undefined,
...JSON.parse(content.toString()),
})
);
},
},
],
}),
new HtmlWebpackPlugin({
template: "src/options.html",
filename: "options.html",
chunks: ["options"],
}),
mode !== "development" &&
new ZipPlugin({
path: path.join(__dirname, "releases"),
filename: `ptt-${process.env.npm_package_version}.zip`,
}),
].filter(Boolean),
};
};