66 lines
1.5 KiB
TypeScript
66 lines
1.5 KiB
TypeScript
|
import path from "path";
|
||
|
import webpack from "webpack";
|
||
|
|
||
|
import CopyWebpackPlugin from "copy-webpack-plugin";
|
||
|
|
||
|
const node_env = (): "development" | "production" | undefined => {
|
||
|
let env = process.env.NODE_ENV;
|
||
|
if (env === "production") return env;
|
||
|
if (env === "development") return env;
|
||
|
if (env === undefined) return undefined;
|
||
|
|
||
|
console.log(
|
||
|
`Invalid NODE_ENV: ${env}. Can only be production, development, or undefined.`
|
||
|
);
|
||
|
process.exit(1);
|
||
|
};
|
||
|
|
||
|
const options: webpack.Configuration = {
|
||
|
mode: node_env(),
|
||
|
entry: {
|
||
|
popup: path.join(__dirname, "src", "popup.ts"),
|
||
|
background: path.join(__dirname, "src", "background.ts"),
|
||
|
},
|
||
|
output: {
|
||
|
path: path.join(__dirname, "build"),
|
||
|
filename: "[name].bundle.js",
|
||
|
},
|
||
|
|
||
|
resolve: {
|
||
|
extensions: [".ts", ".js"],
|
||
|
},
|
||
|
|
||
|
module: {
|
||
|
rules: [
|
||
|
{
|
||
|
test: /\.tsx?$/,
|
||
|
use: "ts-loader",
|
||
|
exclude: /node_modules/,
|
||
|
},
|
||
|
],
|
||
|
},
|
||
|
|
||
|
plugins: [
|
||
|
new CopyWebpackPlugin({
|
||
|
patterns: [
|
||
|
// Copy the manifest, adding in the version and the description from the
|
||
|
// package.json file.
|
||
|
{
|
||
|
from: "src/manifest.json",
|
||
|
transform: (content, _) => {
|
||
|
const oldContent = JSON.parse(content.toString());
|
||
|
const newContent = {
|
||
|
description: process.env.npm_package_description,
|
||
|
version: process.env.npm_package_version,
|
||
|
...oldContent,
|
||
|
};
|
||
|
return Buffer.from(JSON.stringify(newContent));
|
||
|
},
|
||
|
},
|
||
|
],
|
||
|
}),
|
||
|
],
|
||
|
};
|
||
|
|
||
|
export default options;
|