Skip to content

Build & Assets

The build toolchain — npm scripts, webpack, gulp, JavaScript path aliases — and how AssetManager registers editor, frontend, and dashboard assets.

Styble Pro has three JavaScript bundles (block editor, block frontend, admin dashboard) plus SCSS that is compiled in two ways. This page covers the commands you run and how the compiled output is enqueued.

Prerequisites

Install dependencies once:

bash
npm install

The build uses @wordpress/scripts (webpack under the hood) for JavaScript and Gulp with sass for standalone SCSS.

npm scripts

Development

bash
# Block editor dev server (watch + rebuild) → assets/editor
npm start

# Admin dashboard dev server → assets/dashboard
npm run start:admin

# Watch/compile standalone SCSS (run alongside the dev server)
npx gulp

Production build

bash
# Full build: editor bundle, frontend bundles, block.json copy, dashboard
npm run build

# Individual targets
npm run build:dashboard   # Admin dashboard only → assets/dashboard

# Compile standalone SCSS
npx gulp

npm run build chains several steps (see package.json): it builds the editor bundle to assets/editor, builds per-block frontend bundles (e.g. Advanced Video, Popup Builder) into blocks/assets/js/, copies block JSON, and builds the dashboard. The dashboard build also copies dashboard images first.

Code quality

bash
npm run lint       # Lint src/ with @wordpress/scripts (WordPress preset)
npm run lint:fix   # Auto-fix lint issues
npm run format     # Prettier format src/
ScriptWhat it doesOutput
npm startEditor dev server (watch)assets/editor/
npm run start:adminDashboard dev server (watch)assets/dashboard/
npm run buildFull production build (all bundles)assets/editor/, blocks/assets/js/, assets/dashboard/
npm run build:dashboardDashboard bundle onlyassets/dashboard/
npx gulpCompile standalone SCSSassets/css/, assets/dashboard/
npm run lint / lint:fix / formatJS lint & formatting

Two ways SCSS is compiled

SCSS imported from JavaScript (e.g. src/blocks/style.scss, editor.scss) is handled by webpack during the JS build. Standalone SCSS (admin dashboard styles and the block frontend style.css) is compiled by Gulp — so run npx gulp after editing those files. Gulp skips source files that do not exist.

webpack configuration

webpack.config.js extends the default @wordpress/scripts config and adds path aliases so imports stay short and stable. The entry points are set by the npm scripts (src/blocks/index.js, src/admin/index.js, and per-block frontend.js files).

JavaScript path aliases

The following aliases are configured in webpack.config.js (and mirrored for ESLint):

AliasResolves to
@styble-pro/componentssrc/components/
@styble-pro/controlssrc/controls/controls.js
@styble-pro/constantssrc/controls/constants.js
@styble-pro/hookssrc/hooks/
@styble-pro/iconssrc/icons/icons.js
@styble-pro/blocksIconssrc/icons/blocksIcons.js
@styble-pro/helpFnsrc/blocks/shared/helpFn.js
@styble-pro/registerStybleBlocksrc/blocks/shared/registerStybleBlock.js
@styble-pro/templatessrc/templates/
js
import { registerStybleBlock } from '@styble-pro/registerStybleBlock';
import { __ } from '@wordpress/i18n';
import { StybleSeparatorIcon } from '@styble-pro/blocksIcons';

AssetManager

AssetManager (blocks/Includes/AssetManager.php, namespace ShapedPlugin\StyblePro\Includes) registers and enqueues every compiled asset. It is a singleton booted from Block_Init::init_styble_blocks():

php
$asset_manager = AssetManager::instance();
add_action( 'init', array( $asset_manager, 'register_block_editor_assets' ), 10 );
add_action( 'enqueue_block_editor_assets', array( $asset_manager, 'enqueue_block_assets' ) );
add_action( 'enqueue_block_assets', array( $asset_manager, 'register_frontend_assets' ) );
add_action( 'wp_enqueue_scripts', array( $asset_manager, 'enqueue_global_settings_css' ), 15 );
MethodHookResponsibility
register_block_editor_assets()initRegisters the editor script/styles from assets/editor/ (index.js, index.css, style-index.css).
enqueue_block_assets()enqueue_block_editor_assetsEnqueues the editor bundle in Gutenberg.
register_frontend_assets()enqueue_block_assetsRegisters frontend block scripts/styles.
enqueue_global_settings_css()wp_enqueue_scriptsOutputs global settings CSS variables (handle sp-styble-global-root).

The editor script handle is sp-styble-blocks-editor; its dependencies come from the generated assets/editor/index.asset.php (with WordPress packages — wp-blocks, wp-block-editor, wp-components, wp-i18n, wp-element — as the fallback). Assets are versioned with SP_STYBLE_VERSION for cache busting.

Asset locations

BundleBuilt fromOutput
Block editorsrc/blocks/index.jsassets/editor/
Block frontend (per-block)src/blocks/<block>/frontend.jsblocks/assets/js/
Admin dashboardsrc/admin/index.jsassets/dashboard/
Standalone SCSSblocks/admin/*.scss, blocks/blocks/style.scssassets/dashboard/, assets/css/

Global settings CSS

enqueue_global_settings_css() emits CSS custom properties (e.g. --styble-primary, --sp-styble-font-size-heading-1) from the saved global settings option, falling back to sensible defaults. Blocks reference these variables, so design tokens stay site-wide. See Dynamic CSS Generation and the user-facing Global Settings.

Released under the GPL-2.0-or-later License.