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");
let mode = process.env.NODE_ENV || "development";
let options = {
entry: {
popup: path.join(__dirname, "src", "popup", "popup.ts"),
content_script: path.join(
__dirname,
"src",
"content_script",
"content_script.ts"
),
background: path.join(__dirname, "src", "background.ts"),
},
output: {
path: path.resolve(__dirname, "dist"),
filename: "[name].bundle.js",
},
resolve: {
extensions: [".ts", ".js", ".json"],
},
mode: mode,
devtool: "inline-source-map",
module: {
rules: [
{
test: /\.html$/,
loader: "html-loader",
exclude: /node_modules/,
},
{
test: /\.tsx?$/,
use: "ts-loader",
exclude: /node_modules/,
},
{
test: /\.(c|s[ac])ss\.raw$/i,
use: ["raw-loader", "sass-loader"],
},
{
test: /\.(c|s[ac])ss$/i,
use: ["style-loader", "css-loader", "sass-loader"],
},
],
},
plugins: [
new CopyPlugin({
patterns: [{ from: path.resolve(__dirname, "src", "manifest.json") }],
}),
new HtmlWebpackPlugin({
template: path.join(__dirname, "src", "popup", "popup.html"),
filename: "popup.html",
chunks: ["popup"],
}),
],
};
if (mode !== "development") {
options.plugins.unshift(new CleanWebpackPlugin());
options.plugins.push(
new ZipPlugin({
filename: "addon",
extension: "xpi",
})
);
}
module.exports = options;