swashata / wp-webpack-script

💥🔥📦👩‍💻 An easy to use, pre configured, hackable webpack setup & development server for WordPress themes and plugins.
https://wpack.io
MIT License
407 stars 57 forks source link

wpack project in subdirectory results in broken asset paths #1252

Closed esnz closed 2 years ago

esnz commented 2 years ago

In order to prevent bloating of the theme folder, I put all frontend stuff in a subdirectory called static where there resides my wpack project, however, the paths are broken in my WordPress website. The result is like something below, it prints undefined at the beginning of paths.

undefinedreactapp/assets/logo-5a37ec92.png

However, If I put the wpack project in the base directory of the theme everything works properly.

wpackio.project.js

module.exports = {
  appName: 'test',
  type: 'theme',
  slug: 'test',
  outputPath: 'public',
}

I also can't set outputPath in wpackio.project.js to 'static/public' since it has to be a single directory name as per wpack documentation.

I imagine this problem could be from my php code $this->enqueue = new \WPackio\Enqueue( 'test', 'static/public', '1.0.0', 'theme', false );

I set the output to static/public in WPackio Enqueue instantiation however WordPress still can't produce the correct path. As per documentation, it should be the same as outputPath in wpackio.project.js file but it doesn't make sense in this case.

Any help would be appreciated.