swashata/wp-webpack-script

how to enqueue script with depends?

cloudinstone opened this issue · 2 comments

$enqueue = new \WPackio\Enqueue( 'mytheme', 'dist', '1.0.0', 'theme', __FILE__ );

// not working
$enqueue->enqueue( 'app', 'main', ['bp-api-request'] );

// also not working
$enqueue->enqueue( 'app', 'main', ['js_dep' => 'bp-api-request'] );

// I have to do with native, it's working.
wp_enqueue_script('bp-api-request');
$enqueue->enqueue( 'app', 'main' );

but the depends should enqueue only with my script.

forgive my English :)

I have read this page before I ask the question, but still confusing.

Let assume that I have config two files in wpackio.project.js:

files: [
		{
			name: 'app',
			entry: {
				customize: ['./src/js/customize.js'],
				main: ['./src/main.js'], // Or an array of string (string[])
			},
			webpackConfig: undefined,
		},
	],

then in php:

$assets = $enqueue->getAssets( 'app', 'main', [
	'js' => true,
	'css' => true,
	'js_dep' => [],
	'css_dep' => [],
	'in_footer' => true,
	'media' => 'all',
] );
var_dump($assets);

The results will be:

array (size=2)
  'css' => 
    array (size=2)
      0 => 
        array (size=2)
          'handle' => string 'wpackio_mythemeapp_app__vendors~main_css_style' (length=45)
          'url' => string '//192.168.1.2:3000/wp-content/themes/mytheme/dist/app/vendors~main.css' (length=71)
      1 => 
        array (size=2)
          'handle' => string 'wpackio_mythemeapp_app__main_css_style' (length=37)
          'url' => string '//192.168.1.2:3000/wp-content/themes/mytheme/dist/app/main.css' (length=63)
  'js' => 
    array (size=4)
      0 => 
        array (size=2)
          'handle' => string 'wpackio_mythemeapp_app__runtime_js_script' (length=40)
          'url' => string '//192.168.1.2:3000/wp-content/themes/mytheme/dist/app/runtime.js' (length=65)
      1 => 
        array (size=2)
          'handle' => string 'wpackio_mythemeapp_app__vendors~customize~main_js_script' (length=63)
          'url' => string '//192.168.1.2:3000/wp-content/themes/mytheme/dist/app/vendors~customize-main.js' (length=88)
      2 => 
        array (size=2)
          'handle' => string 'wpackio_mythemeapp_app__vendors~main_js_script' (length=45)
          'url' => string '//192.168.1.2:3000/wp-content/themes/mytheme/dist/app/vendors~main.js' (length=70)
      3 => 
        array (size=2)
          'handle' => string 'wpackio_mythemeapp_app__main_js_script' (length=37)
          'url' => string '//192.168.1.2:3000/wp-content/themes/mytheme/dist/app/main.js' (length=62)

I'm confused that why customize.js is here after I have specified entrypoint to 'main'.