File: //var/www/quadcode-site/webpack.config.js
const path = require('path');
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 FileManagerPlugin = require('filemanager-webpack-plugin');
const fs = require('fs');
const PATHS = {
src: path.join(__dirname, './src'),
dist: path.join(__dirname, './dist'),
distLp: path.join(__dirname, './lp'),
};
const lpArray = [
'ifx-landing.html',
'white-label-cfd-broker.html',
'white-label-cfd-broker2.html',
'prop-trading-whitelabel.html',
'saas-landing.html',
'saas-landing_wlbroker.html',
'saas-landing_wlcrypto.html',
'saas-landing_wlforex.html',
'affiliate_traffic.html',
'saas2-landing.html',
'saas_request.html',
'wl-broker_landing.html',
'white-label_landing.html',
];
const isProd = process.env.NODE_ENV === 'production';
const PAGES = fs.readdirSync(PATHS.src).filter(fileName => fileName.endsWith('.html'));
let PAGES_MAIN = PAGES.filter(item => !lpArray.includes(item));
let PAGES_LP = PAGES.filter(item => lpArray.includes(item));
const excludeChunks = (pageName) => {
switch (pageName) {
case 'numbers.html':
return ['ifx', 'saas', 'news', 'saas_request', 'affiliate_traffic', 'whiteLabel'];
case 'news.html':
case 'news-banking.html':
case 'news-brokerage.html':
case 'news-holding.html':
case 'news-saas.html':
case 'news-1.html':
case 'news-2.html':
case 'news-3.html':
case 'news-4.html':
case 'news-5.html':
case 'news-6.html':
case 'news-7.html':
case 'news-8.html':
return ['ifx', 'saas', 'main', 'schedule', 'saas_request', 'affiliate_traffic', 'whiteLabel'];
case 'ifx-landing.html':
return ['main', 'saas', 'schedule', 'news', 'saas_request', 'affiliate_traffic', 'whiteLabel'];
case 'saas-landing.html':
case 'saas-landing_wlbroker.html':
case 'saas-landing_wlcrypto.html':
case 'saas-landing_wlforex.html':
case 'wl-broker_landing.html':
case 'white-label_landing.html':
case 'saas2-landing.html':
return ['main', 'ifx', 'schedule', 'news', 'saas_request', 'affiliate_traffic', 'whiteLabel'];
case 'affiliate_traffic.html':
return ['main', 'ifx', 'schedule', 'news', 'saas_request', 'saas', 'whiteLabel'];
case 'saas_request.html':
return ['main', 'ifx', 'schedule', 'news', 'saas', 'affiliate_traffic', 'whiteLabel'];
case 'white-label-cfd-broker.html':
case 'white-label-cfd-broker2.html':
case 'white-label-broker.html':
case 'prop-trading-whitelabel.html':
return ['main', 'ifx', 'schedule', 'news', 'saas', 'saas_request', 'affiliate_traffic'];
default:
return ['schedule', 'ifx', 'saas', 'news', 'saas_request', 'affiliate_traffic', 'whiteLabel'];
}
}
const renderPage = (page) => {
switch (page) {
case 'ifx-landing.html':
return `./ifx.html`;
case 'white-label-cfd-broker.html':
return `./white-label-cfd-broker.html`;
case 'white-label-cfd-broker2.html':
return `./white-label-cfd-broker2.html`;
case 'white-label-broker.html':
return `./white-label-broker.html`;
case 'prop-trading-whitelabel.html':
return `./prop-trading-whitelabel.html`;
case 'saas-landing.html':
return `./saas.html`;
case 'saas-landing_wlbroker.html':
return `./saas_wlbroker.html`;
case 'saas-landing_wlcrypto.html':
return `./saas_wlcrypto.html`;
case 'saas-landing_wlforex.html':
return `./saas_wlforex.html`;
case 'affiliate_traffic.html':
return `./affiliate_traffic.html`;
case 'saas2-landing.html':
return `./saas2.html`;
case 'saas_request.html':
return `./saas_request.html`;
case 'wl-broker_landing.html':
return `./wl-broker.html`;
case 'white-label_landing.html':
return `./white-label.html`;
case 'news-banking.html':
return `./news/banking.html`;
case 'news-brokerage.html':
return `./news/brokerage.html`;
case 'news-holding.html':
return `./news/holding.html`;
case 'news-saas.html':
return `./news/saas.html`;
case 'news-1.html':
return `./news/quadcode-saas-receives-uf-award-for-best-all-in-on-broke.html`;
case 'news-2.html':
return `./news/quadcode-saas-debuts-at-ifx-expo.html`;
case 'news-3.html':
return `./news/quadcode-partners-with-pavlos-kontides-to-support-young-sailing-athletes.html`;
default:
return `./${page}`;
}
}
const baseConfig = {
mode: process.env.NODE_ENV,
cache: true,
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: ['babel-loader'],
},
{
test: /\.(?:ico|gif|png|jpg|jpeg|svg|mp4|webp)$/i,
type: 'asset/resource',
},
{
test: /\.(woff(2)?|eot|ttf|otf|)$/,
type: 'asset/inline',
},
{
test: /\.(scss|css)$/,
use: [
{
loader: MiniCssExtractPlugin.loader
},
{
loader: 'css-loader'
},
{
loader: 'postcss-loader'
},
{
loader: 'sass-loader'
},
],
},
],
},
devtool: isProd ? false : 'eval',
optimization: {
minimize: isProd,
},
}
module.exports = [
{
...baseConfig,
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',
},
plugins: [
...PAGES_MAIN.map(page => new HtmlWebpackPlugin({
template: `${PATHS.src}/${page}`,
minify: false,
filename: renderPage(page),
excludeChunks: excludeChunks(page),
})),
new CleanWebpackPlugin(),
new MiniCssExtractPlugin({
filename: '[name].[fullhash].css',
}),
new CopyPlugin({
patterns: [
{
from: `${PATHS.src}/assets`,
to: `${PATHS.dist}/assets`,
globOptions: {
ignore: ['**.html'],
},
noErrorOnMissing: true,
},
],
}),
new FileManagerPlugin({
events: {
onStart: [
{
delete: [
`${PATHS.dist}/lp`,
]
},
],
onEnd: {
copy: [
{
source: `${PATHS.distLp}`,
destination: `${PATHS.dist}/lp`,
},
],
delete: [
`${PATHS.distLp}`,
]
}
}
}),
],
},
{
...baseConfig,
entry: {
ifx: `${PATHS.src}/index-ifx.js`,
saas: `${PATHS.src}/index-saas.js`,
saas_request: `${PATHS.src}/index-saas_request.js`,
affiliate_traffic: `${PATHS.src}/index-affiliate_traffic.js`,
whiteLabel: `${PATHS.src}/index-white-label-cfd-broker.js`,
},
output: {
path: PATHS.distLp,
filename: './lp/[name].[fullhash].js',
},
plugins: [
...PAGES_LP.map(page => new HtmlWebpackPlugin({
template: `${PATHS.src}/${page}`,
minify: false,
filename: renderPage(page),
excludeChunks: excludeChunks(page),
})),
new CleanWebpackPlugin(),
new MiniCssExtractPlugin({
filename: './lp/[name].[fullhash].css',
}),
new CopyPlugin({
patterns: [
{
from: `${PATHS.src}/assets`,
to: `${PATHS.distLp}/assets`,
globOptions: {
ignore: ['**.html'],
},
noErrorOnMissing: true,
},
],
}),
new FileManagerPlugin({
events: {
onEnd: {
copy: [
{
source: `${PATHS.distLp}/lp`,
destination: `${PATHS.distLp}`,
},
],
delete: [
`${PATHS.distLp}/lp`,
]
}
}
}),
],
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: ['babel-loader'],
},
{
test: /\.(?:ico|gif|png|jpg|jpeg|svg|mp4|webp)$/i,
type: 'asset/resource',
generator: {
filename: './lp/[hash][ext]'
}
},
{
test: /\.(woff(2)?|eot|ttf|otf|)$/,
type: 'asset/inline',
generator: {
filename: './lp/[hash][ext]'
}
},
{
test: /\.(scss|css)$/,
use: [
{
loader: MiniCssExtractPlugin.loader
},
{
loader: 'css-loader'
},
{
loader: 'postcss-loader'
},
{
loader: 'sass-loader'
},
],
},
],
},
},
];