Utility helpers for managing dynamic Webpack entry points in WordPress projects.
Built on top of @wordpress/scripts, this package simplifies handling of JavaScript and CSS/SCSS assets with flexible folder mapping and exclusions.
This package is hosted on GitHub Packages, not on the public npm registry.
That means you need to configure authentication before you can install or publish it.
Create a file named .npmrc in your project root (or edit your global .npmrc) and add the following content:
@writepoetry:registry=https://npm.pkg.github.com/
//npm.pkg.github.com/:_authToken=YOUR_GITHUB_TOKENReplace YOUR_GITHUB_TOKEN with a GitHub Personal Access Token that has at least:
read:packagesto install,write:packagesto publish.
⚠️ Never commit.npmrcwith a real token into your repository.
npm install @writepoetry/webpack-utils --save-devRequires @wordpress/scripts as a peer dependency.
- Dynamically collect assets (
.js,.ts,.jsx,.tsx,.scss,.css) from yoursrcdirectory. - Exclude specific folders from being processed.
- Remap folder paths to custom namespaces.
- Utility to detect
--output-pathfrom CLI arguments. - Excludes underscore-prefixed files and direcotries: Any file starting with _ (e.g., _variables.scss, _mixins.scss, _partial.js) is automatically skipped during asset collection.
Scans the project source path (from @wordpress/scripts) and builds an object of entry points.
Options:
excludeDirs: string[]Additional directories to exclude (default:['blocks']).remapDirs: Record<string,string>Mapping of directory prefixes to alternate names in the generated chunk keys.
Returns:
Object.<string, string> — mapping of chunk names → absolute file paths.
Example:
const { getAllAssets } = require('@writepoetry/webpack-utils');
module.exports = {
entry: {
...getAllAssets({
excludeDirs: ['vendor'],
remapDirs: {
'js': 'scripts',
'scss': 'styles',
},
}),
},
};Processes files inside a specific directory. Only returns entries for supported extensions.
Arguments:
dir: stringAbsolute path to the directory to scan.remapDirs: Record<string,string>(optional) Same mapping rules as ingetAllAssets.
Scans process.argv for --output-path=... and returns the value, or null if not found.
const defaultConfig = require('@wordpress/scripts/config/webpack.config');
const { getAllAssets } = require('@writepoetry/webpack-utils');
module.exports = {
...defaultConfig,
entry: {
...getAllAssets({
remapDirs: {
'js': 'scripts',
'scss': 'styles',
},
}),
},
};This project is released under the MIT License — free to use, modify, and distribute for any purpose without restrictions.
MIT © WritePoetry