Create New Item
Item Type
File
Folder
Item Name
Search file in folder and subfolders...
Are you sure want to rename?
File Manager
/
wp-content
/
plugins
/
generateblocks
/
config
:
webpack-dependency-extraction.js
Advanced Search
Upload
New Item
Settings
Back
Back Up
Advanced Editor
Save
const WPDependencyExtractionWebpackPlugin = require( '@wordpress/dependency-extraction-webpack-plugin' ); class DependencyExtractionWebpackPlugin extends WPDependencyExtractionWebpackPlugin { /** * Extend the default stringify behavior to sort dependencies by name before returning them. * * @param {any} asset Asset Data * @return {string} Stringified asset data suitable for output */ stringify( asset ) { const prefix = 'generateblocks-'; const sortedDeps = asset.dependencies.sort( ( a, b ) => { const aMatches = a.startsWith( prefix ); const bMatches = b.startsWith( prefix ); if ( aMatches && ! bMatches ) { return 1; } if ( bMatches && ! aMatches ) { return -1; } return a.localeCompare( b ); } ); const updatedAsset = { ...asset, dependencies: sortedDeps }; // Fallback to the original method with the updated asset. return super.stringify( updatedAsset ); } } module.exports = DependencyExtractionWebpackPlugin;