Unable to load admin styles in a WordPress block plugin
00:23 27 Sep 2024

I am using this code to enqueue my WordPress admin specific stylesheet.

function enqueue_neatwp_admin_styles() {
    wp_enqueue_style( 'plugin-admin-style', plugin_dir_url( __FILE__ ) . 'build/styles/admin.css', array(), '1.0.0' );
}
add_action( 'admin_enqueue_scripts', 'enqueue_plugin_admin_styles' );

This works if there is already a CSS file in the build/styles directory. However, the npm run start command will not copy the CSS file in the src/styles directory to the build/styles directory.

I cannot use the src/styles directory link because I am guessing the plugin will only ship with the contents of the build directory.

How do I ensure that my admin CSS is included and loaded?

Thanks.

css wordpress wordpress-gutenberg