0

I'm going through @wordpress/scripts but it's not clear to me how to emit a unique 'build/output.js' which would combine / merge all the assets (admin and plugins) through webpack 4. Let me explain.

I'm using sage, with webpack and in my config.json there is something like:

  "entry": {
    "main": [
      "./scripts/main.js",
      "./styles/main.scss"
    ],
    "customizer": [
      "./scripts/customizer.js"
    ],
    "admin": [
      "./scripts/admin.js"
    ]
  },

Where admin.jsshould contain the emitted resource containing all admin assets. Following the documentation I should enqueue like:

if (is_admin()) {
    wp_enqueue_script('sage/admin.js', asset_path('scripts/admin.js'), ['jquery'], null, true);
}

and in the admin.js itself I assume I would put my imports like:

import './plugins/plugin-name/whatever.js';
import './plugins/plugin-name/whatever-2.js';

using @wordpress/scripts to include core assets and dequeueing/deregistering everything in first place, from admin and plugins. Is this a good way to proceed?

  • Anybody? Small suggestions? – huraji May 26 at 9:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.