UNPKG

chrome-ext-react

Version:
82 lines (79 loc) 1.95 kB
const path = require("path"); const CopyPlugin = require("copy-webpack-plugin"); const HtmlPlugin = require("html-webpack-plugin"); const { CleanWebpackPlugin } = require("clean-webpack-plugin"); const NodePolyfillPlugin = require("node-polyfill-webpack-plugin"); module.exports = { entry: { popup: path.resolve("src/popup/popup.tsx"), options: path.resolve("src/options/options.tsx"), background: path.resolve("src/background/background.ts"), contentScript: path.resolve("src/content/contentScript.ts"), }, module: { rules: [ { test: /\.tsx?$/, use: "ts-loader", exclude: /node_modules/, }, { test: /\.css$/i, use: ["style-loader", "css-loader", "postcss-loader"], }, { test: /\.(jpg|jpeg|png|svg)$/, type: "asset/resource", }, { test: /\.(woff|woff2|eot|ttf)$/, type: "asset/resource", generator: { filename: "assets/fonts/[name][ext][query]", }, }, ], }, resolve: { extensions: [".tsx", ".ts", ".js"], }, plugins: [ new CleanWebpackPlugin({ cleanStaleWebpackAssets: false, }), new CopyPlugin({ patterns: [ { from: path.resolve("src/static"), to: path.resolve("dist"), }, { from: path.resolve("src/content/contentStyle.css"), to: path.resolve("dist"), }, ], }), new NodePolyfillPlugin(), ...getHtmlPlugins(["popup", "options"]), ], output: { filename: "[name].js", path: path.resolve("dist"), }, optimization: { splitChunks: { chunks(chunk) { return chunk.name !== "contentScript" && chunk.name !== "background"; }, }, }, }; function getHtmlPlugins(chunks) { return chunks.map( (chunk) => new HtmlPlugin({ filename: `${chunk}.html`, chunks: [chunk], }) ); }