Skip to content
This repository has been archived by the owner on May 2, 2022. It is now read-only.

Add @wordpress/scripts like auto generation of wp script dependencies #185

Open
fabiankaegy opened this issue Apr 27, 2020 · 3 comments
Open

Comments

@fabiankaegy
Copy link
Member

Is your enhancement related to a problem? Please describe.

It's always a struggle manual having to manage the different dependencies a js file needs. (eg. wp-components, wp-hooks etc.) Just having them auto generate the same way the @wordpress/scripts package does it would be very cool. Also the generated version would improve the workflow a bunch not having to clear cashes all the time.

Describe the solution you'd like

Implementing something like the @wordpress/scripts package would be really cool.

Using the impost syntax
import { Button } from '@wordpress/scripts that then automatically generated a PHP file that has the array for all the dependencies in it.

The generated PHP file would live inside the build folder and would look something like this

return array(
    'dependencies' => array(
        'wp-block-editor',
        'wp-blocks',
        'wp-components',
        'wp-element',
        'wp-polyfill'
    ),
    'version' => 'f76a969d50f965d0c766b177874f89cc'
);

This would then allow us to do the following when actually enqueueing:

$dir = dirname( __FILE__ );

$script_asset_path = "$dir/build/index.asset.php";

$script_asset = include $script_asset_path;

wp_register_script(
        'handle_name',
        plugins_url( '/build/index.js', __FILE__ ),
        $script_asset['dependencies'],
        $script_asset['version'],
        false
);
@nicholasio
Copy link
Member

nicholasio commented Apr 27, 2020

@samikeijonen @ivankristianto This could be something to potentially consider for that 10up-scripts thing we were talking about.

@samikeijonen
Copy link
Contributor

Yep, we have talked this couple of times.

I don't see this as top priority for 10up-scripts but definitely something to keep in mind.

What I don't like in wp-scripts system that it generates cache busting version number only for JS files.

If I remember correctly wp-scripts or webpack-helpers manually add dependencies list so we could use import { Button } from '@wordpress/scripts.

And webpack would still end up reading it from wp.scripts.

@ryanwelcher
Copy link
Contributor

This is big +1 from me.

Perhaps, instead of the whole @wordpress/scripts package we can start with just the DependencyExtractionPlugin similar to 10up/plugin-scaffold#109?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants