File: //var/www/quadcode/frontend/webpack.config.js
const webpack = require("webpack");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CopyPlugin = require("copy-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const HtmlReplaceWebpackPlugin = require("html-replace-webpack-plugin");
const fs = require("fs");
require("dotenv").config({ path: "./../.env" });
const {
PATHS,
lpArray,
excludeChunks,
renderPage,
getCommonRules,
} = require("./webpack.constants");
const isProd = process.env.NODE_ENV === "production";
const PAGES = fs
.readdirSync(PATHS.src)
.filter((fileName) => fileName.endsWith(".html"));
const PAGES_MAIN = PAGES.filter((item) => !lpArray.includes(item));
const PAGES_LP = PAGES.filter((item) => lpArray.includes(item));
const baseConfig = {
mode: process.env.NODE_ENV,
cache: true,
devtool: isProd ? false : "eval",
optimization: {
minimize: isProd,
},
plugins: [
new webpack.DefinePlugin({
"process.env": JSON.stringify(process.env),
}),
new HtmlReplaceWebpackPlugin([
{
pattern: /<!-- @secret (\w*?) -->/gi,
replacement: (match, p1) => process.env[p1] || "",
},
]),
new CleanWebpackPlugin(),
new MiniCssExtractPlugin({
filename: "[name].[fullhash].css",
}),
],
};
module.exports = [
{
...baseConfig,
name: "website",
devServer: {
static: {
directory: PATHS.dist,
},
open: true,
compress: true,
port: 3000,
},
entry: {
main: `${PATHS.src}/index.js`,
schedule: `${PATHS.src}/index-schedule.js`,
news: `${PATHS.src}/index-news.js`,
whiteLabel: `${PATHS.src}/index-white-label-cfd-broker.js`,
},
output: {
path: PATHS.dist,
filename: "[name].[fullhash].js",
},
module: {
rules: getCommonRules(),
},
plugins: [
...baseConfig.plugins,
...PAGES_MAIN.map(
(page) =>
new HtmlWebpackPlugin({
template: `${PATHS.src}/${page}`,
minify: false,
filename: renderPage(page),
excludeChunks: excludeChunks(page),
})
),
new CopyPlugin({
patterns: [
{
from: `${PATHS.src}/assets`,
to: `${PATHS.dist}/assets`,
globOptions: {
ignore: ["**.html"],
},
noErrorOnMissing: true,
},
],
}),
],
},
{
...baseConfig,
name: "landings",
dependencies: ["website"],
entry: {
ifx: `${PATHS.src}/index-ifx.js`,
saas: `${PATHS.src}/index-saas.js`,
saas_request: `${PATHS.src}/index-saas_request.js`,
affiliate: `${PATHS.src}/index-affiliate.js`,
affiliate_traffic: `${PATHS.src}/index-affiliate_traffic.js`,
affiliate_broker: `${PATHS.src}/index-affiliate_broker.js`,
white_label_brokerage: `${PATHS.src}/index-white_label_brokerage.js`,
"digital-currency-brokerage": `${PATHS.src}/index-digital_currency_brokerage.js`,
whiteLabel: `${PATHS.src}/index-white-label-cfd-broker.js`,
freeBrokerage: `${PATHS.src}/index-free-brokerage.js`,
},
output: {
path: PATHS.distLp,
filename: "[name].[fullhash].js",
publicPath: "/lp/",
},
module: {
rules: getCommonRules(),
},
plugins: [
...baseConfig.plugins,
...PAGES_LP.map(
(page) =>
new HtmlWebpackPlugin({
template: `${PATHS.src}/${page}`,
minify: false,
filename: renderPage(page),
excludeChunks: excludeChunks(page),
publicPath: "/lp/",
})
),
new CopyPlugin({
patterns: [
{
from: `${PATHS.src}/assets`,
to: `${PATHS.distLp}/assets`,
globOptions: {
ignore: ["**.html"],
},
noErrorOnMissing: true,
},
],
}),
],
},
];