@byteever/scripts v2.0.7
@byteever/scripts
β‘ Minimal, opinionated Webpack config builder for WordPress plugin and theme development β powered by
@wordpress/scripts.
π Features
- β
Extends
@wordpress/scriptswith zero boilerplate - β
Smart file discovery from the
resources/directory - β Separate handling of admin, frontend, shared, and vendor files
- β Auto-detection of client and source scripts
- β Automatically compiles block files to PHP
- β Copies fonts and images automatically
- β Removes empty JS files generated from SCSS-only entries
- β
Streamlined progress output with
webpackbar - β
Trims unused timezone data from
moment-timezone
π¦ Installation
npm install @byteever/scripts --save-dev
npm install @wordpress/scripts --save-devπ Usage
In your plugin or theme root:
// webpack.config.js
const baseConfig = require('@wordpress/scripts/config/webpack.config');
const createConfig = require('@byteever/scripts');
module.exports = createConfig(baseConfig);π Source Auto-Discovery (Default Behavior)
This package automatically scans the resources/ directory to detect entry points for Webpack, following a clear priority-based pattern.
π§© For scripts/ and styles/ folders:
- If a folder (like
scripts/admin/orstyles/frontend/) contains a file namedindex.js,index.jsx, orindex.ts, that file will be used as the entry point. - If no
indexfile is found, it will then look one level deeper inside that folder for any file that: - Does not start with an underscore (_) - Has one of these extensions:.js,.jsx,.ts,.scss,.sass, or.css
π§© For the client/ folder:
- It checks each top-level subdirectory inside
client/(such asclient/admin/) for anindex.js,index.jsx, orindex.tsfile. - If not found, it looks deeper into nested directories within that client subfolder for the same kind of
indexfiles.
π§© For the blocks/ folder:
- If a
blocks/directory exists insideresources/, it will automatically compile all supported block files. - The output will be saved as PHP files in the
assets/blocks/directory.
β This provides seamless support for custom Gutenberg blocks.
π Manual Entry Support
You can optionally pass a second argument to createConfig() to override or extend the default auto-discovered entries.
π§° Option 1: Replace all entries with a custom object
module.exports = createConfig(baseConfig, {
'admin/settings': './custom/settings.js',
'admin/styles': './custom/settings.scss',
});This disables auto-discovery and will produce:
assets/scripts/admin-settings.js
assets/styles/admin-styles.cssπ§ Format:
{
[outputName]: [sourceFilePath]
}Example:
{
'client/frontend-dashboard': './client/frontend/dashboard/index.js',
'scripts/admin-init': './scripts/admin/init.ts',
'styles/frontend-main': './styles/frontend/main.scss',
}π§° Option 2: Extend discovered entries using a callback
Instead of replacing entries, you can extend the default ones like this:
module.exports = createConfig(baseConfig, (entries) => ({
...entries,
'scripts/chartjs': './node_modules/chart.js/dist/Chart.js',
'styles/jquery-ui': [
'./node_modules/jquery-ui/themes/base/theme.css',
'./node_modules/jquery-ui/themes/base/datepicker.css',
],
}));This gives you full programmatic control to modify, filter, or merge the discovered entries before Webpack runs.
π§ File Naming & Output Logic
β
scripts/ and styles/ directories
Handled smartly based on folder name:
scripts/admin/index.jsβscripts/admin.jsscripts/frontend/menu.jsβscripts/frontend-menu.jsstyles/shared/forms.scssβstyles/shared-forms.cssstyles/vendor/bootstrap.scssβstyles/vendor-bootstrap.css- If a filename duplicates the folder name (
scripts/admin/admin.js), itβs deduplicated automatically.
β
client/ entries
- Output format:
client/admin-dashboard.js,client/frontend-settings.js, etc. - For nested files, the domain (
admin,frontend) is always prepended automatically. - Files under non-admin/frontend folders keep their full compound name (e.g.
client/shared-modal.js) - The
client/folder is intended for React-based applications.
π Asset Copying (Built-in)
Automatically copies source assets to the correct output location:
| Source | Destination |
|---|---|
resources/images/*.svg | assets/images/ |
resources/fonts/*.woff | assets/fonts/ |
No config required.
π Included Plugins
webpackbarβ Clean terminal outputcopy-webpack-pluginβ Images & fontswebpack-remove-empty-scriptsβ Prevent.jsfiles from SCSS-only entriesmoment-timezone-data-webpack-pluginβ Smaller moment builds
π€ Author
Built and maintained by ByteEver