101 lines
2 KiB
JavaScript
101 lines
2 KiB
JavaScript
const path = require("path");
|
|
|
|
const HtmlWebpackPlugin = require("html-webpack-plugin");
|
|
const CopyPlugin = require("copy-webpack-plugin");
|
|
const ZipPlugin = require("zip-webpack-plugin");
|
|
|
|
let mode = process.env.NODE_ENV || "development";
|
|
|
|
let options = {
|
|
entry: {
|
|
popup: path.join(__dirname, "src", "frontend", "popup", "popup.ts"),
|
|
options: path.join(__dirname, "src", "frontend", "options", "options.ts"),
|
|
background: path.join(__dirname, "src", "background", "background.ts"),
|
|
},
|
|
output: {
|
|
path: path.resolve(__dirname, "dist"),
|
|
filename: "[name].bundle.js",
|
|
},
|
|
resolve: {
|
|
alias: {
|
|
svelte: path.resolve("node_modules", "svelte"),
|
|
},
|
|
extensions: [".ts", ".mjs", ".js", ".json", ".svelte"],
|
|
},
|
|
mode: mode,
|
|
devtool: "inline-source-map",
|
|
module: {
|
|
rules: [
|
|
{
|
|
test: /\.tsx?$/,
|
|
|
|
oneOf: [
|
|
{
|
|
resourceQuery: /file/,
|
|
use: [
|
|
{
|
|
loader: "worklet-loader",
|
|
options: {
|
|
name: "[name]_cs.js",
|
|
},
|
|
},
|
|
"ts-loader",
|
|
],
|
|
},
|
|
{
|
|
use: "ts-loader",
|
|
},
|
|
],
|
|
exclude: /node_modules/,
|
|
},
|
|
{
|
|
test: /\.(c|s[ac])ss$/i,
|
|
use: ["style-loader", "css-loader", "sass-loader"],
|
|
},
|
|
{
|
|
test: /\.(html|svelte)$/,
|
|
use: {
|
|
loader: "svelte-loader",
|
|
options: {
|
|
preprocess: require("svelte-preprocess")({}),
|
|
},
|
|
},
|
|
},
|
|
{
|
|
// required to prevent errors from Svelte on Webpack 5+, omit on Webpack 4
|
|
test: /node_modules\/svelte\/.*\.mjs$/,
|
|
resolve: {
|
|
fullySpecified: false,
|
|
},
|
|
},
|
|
],
|
|
},
|
|
plugins: [
|
|
new CopyPlugin({
|
|
patterns: [
|
|
{
|
|
from: path.resolve(__dirname, "src", "manifest.json"),
|
|
},
|
|
],
|
|
}),
|
|
new HtmlWebpackPlugin({
|
|
filename: "popup.html",
|
|
chunks: ["popup"],
|
|
}),
|
|
new HtmlWebpackPlugin({
|
|
filename: "options.html",
|
|
chunks: ["options"],
|
|
}),
|
|
],
|
|
};
|
|
|
|
if (mode !== "development") {
|
|
options.plugins.push(
|
|
new ZipPlugin({
|
|
filename: "addon",
|
|
extension: "xpi",
|
|
})
|
|
);
|
|
}
|
|
|
|
module.exports = options;
|