Skip to content

Remove static file tags from index.html when "Update Dev-Environment" #65

Open

Description

@dylanlawrence

Just as "nice to have" feature
When then index.html is generated it puts in [script, link] tags to files [js, css] that aren't available and leads to errors in the browser dev console.
I'm also using [suspend, lazy etc] which creates many more files.
It would nice if the generate process could just exclude these files.

Activity

  1. dylanlawrence commented on Oct 24, 2024

    @dylanlawrence
    ContributorAuthor

    So I see there is already code for this to work, however it's matching id='rp-rea... where most of mine are double quote id="rp-rea.... Maybe it's a theme output thing ¯\_(ツ)_/¯

    I think it's probably something better handled with the dom.
    This works for me.

    reactpress/admin/Controller.php #207

    $dom = new \DOMDocument();
    libxml_use_internal_errors(true);
    $dom->loadHTML(wp_remote_retrieve_body($resp));
    $selector = new \DOMXPath($dom);
    foreach ($selector->query('//*[starts-with(@id, "rp-react-app-asset-")]') as $node) {
          $node->parentNode->removeChild($node);
    }
    $filtered_contents = $dom->saveHTML();
    
    //.     $file_contents = wp_remote_retrieve_body($resp);
    //      $file_contents_arr = explode(PHP_EOL, $file_contents);
    //      // filter all build assets out of the file, that they don't conflict
    //      // with the dev assets.
    //      $filtered_arr = array_filter($file_contents_arr, fn ($el) => !strpos($el, "id='rp-react-app-asset-"));
    //      $filtered_contents =  implode(PHP_EOL, $filtered_arr);
  2. BlairCooper commented on Jan 29, 2025

    @BlairCooper
    Contributor

    Another option might be replace strpos() with a regular express match.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions