fleet/ee/fleetd-chrome/webpack.common.js
Zach Wasserman 8bea7137af
fleetd-chrome release workflows (#16020)
Add GitHub Actions for releasing fleetd-chrome beta and production. See
the included README updates for details.

This was tested with an `on: pull-request` trigger for the beta workflow
which is now removed for merging into the repo.
2024-01-16 11:56:43 -08:00

93 lines
2.6 KiB
JavaScript

// Some of this webpack config inspired by MIT licensed
// https://github.com/samuelsimoes/chrome-extension-webpack-boilerplate
import { resolve as _resolve, dirname } from "path";
import { fileURLToPath } from "url";
import CopyWebpackPlugin from "copy-webpack-plugin";
import HtmlWebpackPlugin from "html-webpack-plugin";
import TerserPlugin from "terser-webpack-plugin";
import webpack from "webpack";
import dotenv from "dotenv";
const __dirname = dirname(fileURLToPath(import.meta.url));
export const entry = {
background: "./src/background.ts",
popup: "./src/popup.ts",
};
export const module = {
rules: [
{
test: /\.tsx?$/,
use: "ts-loader",
exclude: /node_modules/,
},
],
};
export const resolve = {
extensions: [".tsx", ".ts", ".js"],
};
export const plugins = [
new webpack.DefinePlugin({
...Object.entries(dotenv.config().parsed).reduce(
(acc, curr) => ({ ...acc, [`${curr[0]}`]: JSON.stringify(curr[1]) }),
{}
),
}),
new CopyWebpackPlugin({
patterns: [
{
from: "./src/manifest.json",
// Set description and version in extension manifest.json from contents of package.json (so
// that there's only one place to update).
transform: function (content, _path) {
return Buffer.from(
JSON.stringify({
...JSON.parse(content.toString()),
description: process.env.npm_package_description,
version: process.env.npm_package_version,
})
);
},
},
{ from: "./src/schema.json" },
{ from: "./src/icons" },
],
}),
new HtmlWebpackPlugin({
template: "./src/popup.html",
filename: "popup.html",
chunks: ["popup"],
}),
];
// Intentionally disabling mangling and leaving source maps in both dev and prod builds because this
// is going to be source available anyway... might as well make debugging easier. This makes
// background.bundle.js be ~350KB instead of ~70KB, but that shouldn't matter much given how rarely
// the JS is downloaded and parsed.
export const devtool = "inline-source-map";
export const optimization = {
usedExports: true,
minimize: true,
minimizer: [
new TerserPlugin({
extractComments: false,
terserOptions: {
compress: {
defaults: false,
unused: true,
},
mangle: false,
format: {
comments: "all",
},
},
}),
],
};
export const output = {
filename: "[name].bundle.js",
path: _resolve(__dirname, "dist"),
chunkFormat: "commonjs",
clean: true,
};