Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange enqueue behaviour, with nothing being enqueued at all. Needs fix in Enqueue.php:297 source #1247

Open
lnilya opened this issue Jan 7, 2022 · 2 comments

Comments

@lnilya
Copy link

lnilya commented Jan 7, 2022

I am not sure what I am doing wrong, but I had numerous plugins and themes already developed with wpack.io (version 5.x) with no issues. This time however whenever I try to enqueue my ts/scss into the backend nothing shows up. I debugged the issue and possibly solved it.

in my wpproject:

name:'referral',
entry: {
	reftable:'./src/js/reftable.tsx',
	reftablestyles:'./src/scss/main.scss',
},

in the plugins main file:

include_once 'vendor/autoload.php';
	global $enq;
	$enq = new \WPackio\Enqueue('dbireferral', 'dist', $ver, 'plugin', __FILE__);

and in the hook to enqueue scripts

add_action('admin_enqueue_scripts', function(){
    global $enq;
    $res = $enq->enqueue('referral', 'reftable', []);
    $enq->enqueue('referral', 'reftablestyles', []);
});

So far pretty standard. However with the current setup it did not work for me. I debugged it and compared it with other plugins I had developed with wpack.io. The reason seems to be in wpacks main php file: Enqueue.php in the getAssets function
It loads the part of the manifest where the js files are all linked.
$enqueue = $manifest['wpackioEp'][ $entryPoint ];
For some reason the manifest looks different for my older plugins vs my current one. And it differs by adding an assets node around the js/css nodes. That way the above code in $enqueue doesn't give any results and nothing is enqueued:
wpackioEp:{ reftable: { assets: { js: [....] .... } } }

If in line 297 you change the enqueue variable it seems to work:
$enqueue = $manifest['wpackioEp'][ $entryPoint ]['assets'];

Maybe it has something to do with versions and how webpack delivers data. or maybe it is specific to backend. But someone should look at it, why this happens.

@lnilya lnilya changed the title Strange enqueue behaviour, with nothing being enqueued at all. Needs fix in Enqueue.php source Strange enqueue behaviour, with nothing being enqueued at all. Needs fix in Enqueue.php:297 source Jan 7, 2022
@lnilya
Copy link
Author

lnilya commented Jan 10, 2022

Confirmed that behaviour.

With "@wpackio/scripts": "6.4.0" (npm) and "wpackio/enqueue": "2.2" (composer) I get the behaviour described above. So I believe something changed in the web pack config and it doesnt work with the php side anymore, which needs a change as described above. Maybe there is a setting to prevent this "assets" node to be created.

With "@wpackio/scripts": "5.0.0" (npm) and "wpackio/enqueue": "2.2" (composer) everything works fine and as expected.

It's a shame that wpack is not really being supported developed anymore. Was such a great library! : /

@swashata
Copy link
Owner

Hello,

With @wpackio/script v6.4.0, you have to use wpackio/enqueue v3.4.0. There has been a change in how manifest json files are generated from the upstream package and the PHP package has been updated accordingly. You can safely upgrade both to the latest version and it should work.

I would appreciate if you'd like to add this to the website documentation.

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

No branches or pull requests

2 participants