humanmade / react-wp-scripts

Integrate create-react-app with your WordPress theme/plugin.
235 stars 32 forks source link

Add new filter to change the port file path #1

Closed igmoweb closed 6 years ago

igmoweb commented 6 years ago

The code assumes that we're always working on a theme but we could be using a plugin. This is an actual case for The Sun.

rmccue commented 6 years ago

Could we make the root directory a parameter to enqueue_assets() instead? e.g. enqueue_assets( __DIR__, 'theme-name', [ 'maybe', 'deps' ] )

rmccue commented 6 years ago

Actually, better idea, let's redesign the interface to this:

<?php
/**
 * @param string $directory Root directory containing `src` directory.
 * @param array $opts {
 *     @type string $handle  Style/script handle. (Default is last part of directory name.)
 *     @type array  $scripts Script dependencies.
 *     @type array  $styles  Style dependencies.
 * }
 */
function enqueue_assets( $directory, $opts = [] );
igmoweb commented 6 years ago

@rmccue enqueue_assets is not enqueuing any style. Do we want to do that? When Webpack is up, we don't need to enqueue styles at all, they are inserted inline

igmoweb commented 6 years ago

@rmccue I pushed a few changes:

  1. I added the interface you said but also an extra base_url param for production builds.
  2. The JS and CSS filenames are now read from assets-manifest.json (for production)
igmoweb commented 6 years ago

@rmccue We've been testing this branch for a few weeks and it's working fine for both, dev and build environments. Do we want to do anything else here?

kadamwhite commented 6 years ago

@igmoweb I incorporated much of this PR into #6 which just landed, could you test out with the latest and let me know if that one supersedes this?

igmoweb commented 6 years ago

Excellent @kadamwhite . Closing here.