2020-07-19 22:40:30 +02:00
|
|
|
const path = require("path");
|
|
|
|
|
|
|
|
const HtmlWebpackPlugin = require("html-webpack-plugin");
|
|
|
|
const CopyPlugin = require("copy-webpack-plugin");
|
|
|
|
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
|
|
|
|
const ZipPlugin = require("zip-webpack-plugin");
|
|
|
|
|
2020-07-23 16:48:51 +02:00
|
|
|
let mode = process.env.NODE_ENV || "development";
|
|
|
|
|
|
|
|
let options = {
|
2020-07-19 22:40:30 +02:00
|
|
|
entry: {
|
2020-07-23 16:48:51 +02:00
|
|
|
popup: path.join(__dirname, "src", "popup", "popup.ts"),
|
2020-07-31 00:29:40 +02:00
|
|
|
content_script: path.join(
|
|
|
|
__dirname,
|
|
|
|
"src",
|
|
|
|
"content_script",
|
|
|
|
"content_script.ts"
|
|
|
|
),
|
2020-07-23 21:00:54 +02:00
|
|
|
background: path.join(__dirname, "src", "background.ts"),
|
2020-07-19 22:40:30 +02:00
|
|
|
},
|
|
|
|
output: {
|
|
|
|
path: path.resolve(__dirname, "dist"),
|
|
|
|
filename: "[name].bundle.js",
|
|
|
|
},
|
2020-07-30 11:55:00 +02:00
|
|
|
resolve: {
|
|
|
|
extensions: [".ts", ".js", ".json"],
|
|
|
|
},
|
2020-07-23 16:48:51 +02:00
|
|
|
mode: mode,
|
2020-07-19 22:40:30 +02:00
|
|
|
devtool: "inline-source-map",
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.html$/,
|
|
|
|
loader: "html-loader",
|
|
|
|
exclude: /node_modules/,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.tsx?$/,
|
|
|
|
use: "ts-loader",
|
|
|
|
exclude: /node_modules/,
|
|
|
|
},
|
2020-07-30 19:49:07 +02:00
|
|
|
{
|
2020-07-31 00:29:40 +02:00
|
|
|
test: /\.(c|s[ac])ss\.raw$/i,
|
|
|
|
use: ["raw-loader", "sass-loader"],
|
2020-07-30 19:49:07 +02:00
|
|
|
},
|
2020-07-23 16:48:51 +02:00
|
|
|
{
|
2020-07-31 00:29:40 +02:00
|
|
|
test: /\.(c|s[ac])ss$/i,
|
2020-07-30 19:49:07 +02:00
|
|
|
use: ["style-loader", "css-loader", "sass-loader"],
|
2020-07-23 16:48:51 +02:00
|
|
|
},
|
2020-07-19 22:40:30 +02:00
|
|
|
],
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new CopyPlugin({
|
|
|
|
patterns: [{ from: path.resolve(__dirname, "src", "manifest.json") }],
|
|
|
|
}),
|
|
|
|
new HtmlWebpackPlugin({
|
2020-07-23 16:48:51 +02:00
|
|
|
template: path.join(__dirname, "src", "popup", "popup.html"),
|
2020-07-19 22:40:30 +02:00
|
|
|
filename: "popup.html",
|
|
|
|
chunks: ["popup"],
|
|
|
|
}),
|
2020-07-23 16:48:51 +02:00
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
if (mode !== "development") {
|
|
|
|
options.plugins.unshift(new CleanWebpackPlugin());
|
|
|
|
options.plugins.push(
|
2020-07-19 22:40:30 +02:00
|
|
|
new ZipPlugin({
|
|
|
|
filename: "addon",
|
|
|
|
extension: "xpi",
|
2020-07-23 16:48:51 +02:00
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = options;
|