Skip to content

Commit

Permalink
Include variations in webpack config & copy all php classes to build
Browse files Browse the repository at this point in the history
  • Loading branch information
carstingaxion committed Sep 21, 2024
1 parent f749adb commit cb45d04
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,41 @@
/**
* External Dependencies
*/
const path = require('path');
const fs = require('fs');
const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');

/**
* WordPress Dependencies
*/
const defaultConfig = require('@wordpress/scripts/config/webpack.config.js');

function getVariationEntries() {
const variationsDir = path.resolve(process.cwd(), 'src', 'variations');
const entries = {};

const variationDirs = fs.readdirSync(variationsDir);
for (const variation of variationDirs) {
const variationPath = path.join(variationsDir, variation);
entries[`variations/${variation}/index`] = path.join(variationPath, 'index.js');
};
return entries;
}

module.exports = {
...defaultConfig,
plugins: [
...defaultConfig.plugins,
new CopyWebpackPlugin({
patterns: [
{
from: 'variations/**/class-*.php',
to: '[path][name][ext]',
context: 'src',
},
],
}),
],
entry: {
...defaultConfig.entry(),
admin_style: path.resolve(process.cwd(), 'src', 'admin.scss'),
Expand All @@ -24,6 +50,8 @@ module.exports = {
),
profile: path.resolve(process.cwd(), 'src/profile', 'index.js'),
profile_style: path.resolve(process.cwd(), 'src/profile', 'style.scss'),
// 'variations/add-to-calendar/index': path.resolve(process.cwd(), 'src/variations/add-to-calendar', 'index.js'),
...getVariationEntries(),
},
module: {
...defaultConfig.module,
Expand Down

0 comments on commit cb45d04

Please sign in to comment.