2021-07-07 13:07:19 -04:00
|
|
|
const path = require('path');
|
|
|
|
const glob = require("glob-all");
|
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
|
|
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
|
|
|
|
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
|
|
|
const BrowserSyncPlugin = require('browser-sync-webpack-plugin');
|
|
|
|
const PurgecssPlugin = require("purgecss-webpack-plugin");
|
2021-07-04 08:27:31 -04:00
|
|
|
|
2021-07-07 13:07:19 -04:00
|
|
|
const isProduction = 'production' === process.env.NODE_ENV;
|
2019-05-23 12:30:31 -04:00
|
|
|
|
|
|
|
// Set the build prefix.
|
|
|
|
let prefix = isProduction ? '.min' : '';
|
|
|
|
|
|
|
|
const config = {
|
2021-07-04 18:16:33 -04:00
|
|
|
entry: './assets/js/main.js',
|
|
|
|
output: {
|
|
|
|
filename: `[name]${prefix}.js`,
|
|
|
|
path: path.resolve(__dirname, 'dist')
|
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.js$/,
|
2021-07-02 11:32:59 -04:00
|
|
|
exclude: /node_modules/,
|
2021-07-04 18:16:33 -04:00
|
|
|
loader: 'babel-loader',
|
|
|
|
options: {
|
|
|
|
presets: [
|
|
|
|
[
|
|
|
|
"@babel/preset-env"
|
|
|
|
]
|
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
2021-07-02 11:32:59 -04:00
|
|
|
{
|
|
|
|
test: /\.[s]?css$/,
|
|
|
|
use: [
|
2021-07-02 12:51:36 -04:00
|
|
|
MiniCssExtractPlugin.loader,
|
|
|
|
"css-loader",
|
|
|
|
"sass-loader",
|
|
|
|
"postcss-loader",
|
|
|
|
],
|
2021-07-04 18:16:33 -04:00
|
|
|
},
|
2021-07-04 08:27:31 -04:00
|
|
|
{
|
|
|
|
test: /\.(woff(2)?|ttf|eot)(\?v=\d+\.\d+\.\d+)?$/,
|
2021-07-22 23:17:31 -04:00
|
|
|
type: 'asset/resource',
|
|
|
|
generator: {
|
|
|
|
filename: 'fonts/[name][ext]'
|
|
|
|
},
|
2021-07-04 08:27:31 -04:00
|
|
|
},
|
2021-07-04 09:26:44 -04:00
|
|
|
{
|
|
|
|
test: /\.svg$/,
|
2021-07-26 11:03:32 -04:00
|
|
|
type: 'asset/resource',
|
|
|
|
generator: {
|
|
|
|
filename: (pathData) => {
|
|
|
|
if (pathData.filename.includes('@mdi')) {
|
|
|
|
return 'images/mdi-[name][ext]';
|
|
|
|
} else if (pathData.filename.includes("bootstrap-icons")) {
|
|
|
|
return 'images/bsi-[name][ext]';
|
|
|
|
} else if (pathData.filename.includes("heroicons")) {
|
|
|
|
if (pathData.filename.includes("outline")) {
|
|
|
|
return 'images/hio-[name][ext]';
|
2021-07-04 09:26:44 -04:00
|
|
|
} else {
|
2021-07-26 11:03:32 -04:00
|
|
|
return 'images/his-[name][ext]';
|
2021-07-04 09:26:44 -04:00
|
|
|
}
|
|
|
|
} else {
|
2021-07-26 11:03:32 -04:00
|
|
|
return 'images/svg-[name][ext]';
|
2021-07-04 09:26:44 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
2021-07-26 11:03:32 -04:00
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'svgo-loader',
|
|
|
|
options: {
|
|
|
|
configFile: path.resolve('svgo.config.js'),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
2021-07-04 09:26:44 -04:00
|
|
|
},
|
2021-07-04 08:27:31 -04:00
|
|
|
]
|
2021-07-04 18:16:33 -04:00
|
|
|
},
|
|
|
|
optimization: {
|
|
|
|
minimizer: ["...", new CssMinimizerPlugin()],
|
|
|
|
},
|
|
|
|
mode: process.env.NODE_ENV,
|
|
|
|
resolve: {
|
|
|
|
alias: {
|
|
|
|
'@' : path.resolve('assets'),
|
|
|
|
'@images': path.resolve('../images')
|
|
|
|
}
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new MiniCssExtractPlugin({ filename: `[name]${prefix}.css` }),
|
|
|
|
new CopyWebpackPlugin({
|
|
|
|
patterns: [{
|
|
|
|
from: './assets/images/',
|
|
|
|
to: 'images',
|
|
|
|
globOptions: {
|
|
|
|
ignore: [
|
|
|
|
'**/.DS_Store'
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
}),
|
2021-07-07 13:07:19 -04:00
|
|
|
].concat(
|
|
|
|
isProduction
|
|
|
|
? [
|
|
|
|
new PurgecssPlugin({
|
|
|
|
paths: glob.sync([
|
|
|
|
'./*.php',
|
|
|
|
'./src/**/*.php',
|
|
|
|
'./page-templates/*.php',
|
|
|
|
'./content-templates/*.php',
|
|
|
|
]),
|
|
|
|
safelist: {
|
|
|
|
greedy: getCSSWhitelistPatterns(),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
]
|
|
|
|
: []
|
|
|
|
)
|
2019-05-23 12:30:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Fire up a local server if requested
|
|
|
|
if (process.env.SERVER) {
|
2021-07-04 18:16:33 -04:00
|
|
|
config.plugins.push(
|
|
|
|
new BrowserSyncPlugin(
|
|
|
|
{
|
2021-07-11 14:29:50 -04:00
|
|
|
proxy: process.env.BSYNC_PROXY || 'localhost',
|
2021-07-04 18:16:33 -04:00
|
|
|
files: [
|
|
|
|
'**/*.php',
|
|
|
|
'**/*.scss'
|
|
|
|
],
|
2021-07-11 14:29:50 -04:00
|
|
|
port: process.env.BSYNC_PORT || 8080,
|
|
|
|
host: process.env.BSYNC_HOST || '127.0.0.1',
|
|
|
|
listen: process.env.BSYNC_LISTEN || '0.0.0.0',
|
2021-11-17 16:44:46 -05:00
|
|
|
// notify: false,
|
|
|
|
// open: false,
|
2021-07-11 14:29:50 -04:00
|
|
|
ui: { port: process.env.BSYNC_UI_PORT || 8081 }
|
2021-07-04 18:16:33 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
2019-05-23 12:30:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List of RegExp patterns for PurgeCSS
|
|
|
|
* @returns {RegExp[]}
|
|
|
|
*/
|
|
|
|
function getCSSWhitelistPatterns() {
|
2021-07-04 18:16:33 -04:00
|
|
|
return [
|
|
|
|
/^home(-.*)?$/,
|
|
|
|
/^blog(-.*)?$/,
|
|
|
|
/^archive(-.*)?$/,
|
|
|
|
/^date(-.*)?$/,
|
|
|
|
/^error404(-.*)?$/,
|
|
|
|
/^admin-bar(-.*)?$/,
|
|
|
|
/^search(-.*)?$/,
|
|
|
|
/^nav(-.*)?$/,
|
|
|
|
/^wp(-.*)?$/,
|
2021-08-04 16:40:42 -04:00
|
|
|
/^has(-.*)?$/,
|
2021-07-04 18:16:33 -04:00
|
|
|
/^screen(-.*)?$/,
|
|
|
|
/^navigation(-.*)?$/,
|
|
|
|
/^(.*)-template(-.*)?$/,
|
|
|
|
/^(.*)?-?single(-.*)?$/,
|
|
|
|
/^postid-(.*)?$/,
|
|
|
|
/^post-(.*)?$/,
|
2021-08-04 16:40:42 -04:00
|
|
|
/^sticky(-.*)?$/,
|
2021-07-04 18:16:33 -04:00
|
|
|
/^attachmentid-(.*)?$/,
|
|
|
|
/^attachment(-.*)?$/,
|
|
|
|
/^page(-.*)?$/,
|
|
|
|
/^(post-type-)?archive(-.*)?$/,
|
|
|
|
/^author(-.*)?$/,
|
|
|
|
/^category(-.*)?$/,
|
|
|
|
/^tag(-.*)?$/,
|
|
|
|
/^menu(-.*)?$/,
|
2021-08-04 16:40:42 -04:00
|
|
|
/^more(-.*)?$/,
|
2021-07-04 18:16:33 -04:00
|
|
|
/^tags(-.*)?$/,
|
|
|
|
/^tax-(.*)?$/,
|
|
|
|
/^term-(.*)?$/,
|
|
|
|
/^date-(.*)?$/,
|
|
|
|
/^(.*)?-?paged(-.*)?$/,
|
|
|
|
/^depth(-.*)?$/,
|
|
|
|
/^children(-.*)?$/,
|
2021-07-10 10:24:05 -04:00
|
|
|
/^hljs(-.*)?$/,
|
2021-07-08 19:19:22 -04:00
|
|
|
/^tek(-.*)?$/,
|
2021-07-10 19:30:03 -04:00
|
|
|
/^html$/,
|
|
|
|
/^body$/,
|
2021-08-04 16:40:42 -04:00
|
|
|
/^figure$/,
|
2021-07-10 19:30:03 -04:00
|
|
|
/^blockquote$/,
|
2021-11-17 16:55:18 -05:00
|
|
|
/^is-active$/,
|
2021-08-04 17:37:24 -04:00
|
|
|
/^collapse$/,
|
|
|
|
/^collapsing$/,
|
2021-08-04 16:40:42 -04:00
|
|
|
/^label$/,
|
2021-07-10 19:54:56 -04:00
|
|
|
/^input$/,
|
2021-08-04 16:40:42 -04:00
|
|
|
/^textarea$/,
|
|
|
|
/^select$/,
|
2021-07-10 19:54:56 -04:00
|
|
|
/^svg$/,
|
|
|
|
/^img$/,
|
2021-07-10 19:30:03 -04:00
|
|
|
/^ul$/,
|
2021-07-10 19:54:56 -04:00
|
|
|
/^li$/,
|
|
|
|
/^p$/,
|
|
|
|
/^a$/,
|
2021-07-10 19:30:03 -04:00
|
|
|
/^h.$/,
|
2021-07-10 19:54:56 -04:00
|
|
|
/^pre$/,
|
|
|
|
/^code$/,
|
2021-07-04 18:16:33 -04:00
|
|
|
];
|
2019-05-23 12:30:31 -04:00
|
|
|
}
|
|
|
|
|
2020-09-25 11:03:04 -04:00
|
|
|
module.exports = config
|