flashlang/webpack.config.js

95 lines
1.9 KiB
JavaScript
Raw Normal View History

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-08-07 13:45:32 +02:00
popup: path.join(__dirname, "src", "frontend", "popup", "popup.ts"),
2020-07-31 00:29:40 +02:00
content_script: path.join(
__dirname,
"src",
2020-08-07 13:45:32 +02:00
"frontend",
2020-07-31 00:29:40 +02:00
"content_script",
"content_script.ts"
),
2020-08-04 00:38:41 +02:00
gtranslate_scraper: path.join(
__dirname,
"src",
"background",
"gtranslate_content_script.ts"
),
background: path.join(__dirname, "src", "background", "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?$/,
2020-08-02 20:48:29 +02:00
oneOf: [
{
resourceQuery: /file/,
2020-08-04 00:38:41 +02:00
use: ["file-loader", "ts-loader"],
type: "javascript/esm",
2020-08-02 20:48:29 +02:00
},
{
use: "ts-loader",
},
],
2020-07-19 22:40:30 +02:00
exclude: /node_modules/,
},
2020-07-23 16:48:51 +02:00
{
2020-07-31 00:29:40 +02:00
test: /\.(c|s[ac])ss$/i,
2020-08-02 20:48:29 +02:00
oneOf: [
{
2020-08-04 00:38:41 +02:00
resourceQuery: /raw/,
use: ["raw-loader", "sass-loader"],
2020-08-02 20:48:29 +02:00
},
{
use: ["style-loader", "css-loader", "sass-loader"],
},
],
},
2020-07-19 22:40:30 +02:00
],
},
plugins: [
new CopyPlugin({
patterns: [{ from: path.resolve(__dirname, "src", "manifest.json") }],
}),
new HtmlWebpackPlugin({
2020-08-07 13:45:32 +02:00
template: path.join(__dirname, "src", "frontend", "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;