const fs = require("fs"); const path = require("path"); const webpack = require("webpack"); const HtmlWebpackPlugin = require("html-webpack-plugin"); const CleanWebpackPlugin = require("clean-webpack-plugin"); const MiniCssExtractPlugin = require("mini-css-extract-plugin"); const PAGE_DIR = path.resolve(__dirname, "src", "pages"); // Collect page configurations const page_files = fs.readdirSync(PAGE_DIR); const pages = page_files.map(page => JSON.parse(fs.readFileSync( path.resolve(PAGE_DIR, page), {encoding: "UTF-8"} ))); module.exports = { entry: { index: "./src/index/index.js", mail: "./src/mail/mail.js", startpage: "./src/startpage/startpage.js" }, output: { filename: "[name].bundle.js", path: path.resolve(__dirname, "dist", "static") }, plugins: [ new CleanWebpackPlugin("dist"), new webpack.ProvidePlugin({ $: "jquery", jQuery: "jquery" }), new MiniCssExtractPlugin() ].concat(pages.map(page => new HtmlWebpackPlugin(page))), module: { rules: [ { test: /\.js$/, exclude: /{node_modules}/, use: { loader: "babel-loader", options: { presets: ["babel-preset-env"] } } }, { test: /.scss$/, use: [{ loader: MiniCssExtractPlugin.loader, options: { output: { path: path.resolve(__dirname, "dist", "static") } } }, { loader: "css-loader" }, { loader: "postcss-loader", options: { plugins: () => [ require("precss"), require("autoprefixer") ] } }, { loader: "sass-loader" }] }, { test: /.html$/, use: [{ loader: "html-loader" }] }, { test: /.pug$/, use: [{ loader: "pug-loader" }] }, { test: /\.(eot|svg|ttf|woff|woff2)$/, use: [{ loader: "file-loader", options: { outputPath: "static" } }] } ] } };