Roots Discourse

Wp_localize_script into main.js in production

Hey everybody,

I’m trying to localize some data from wordpress to my javascript code.

    wp_enqueue_script('pw-script', asset_path('scripts/main.js'));
    $dates = get_product_restrictions();
    wp_localize_script('pw-script', 'limit_calendar_dates', array(
        'dates' => $dates
    ));

in a standard build i have main.js in dist folder and therefore it all works well.
However, in production mode my main.js file name changes from main.js to something like main_12326456.js since the cache-busting mechanism kicks in production.
The problem is that my wp_enqueue_script creates a second main.js file and misses the goal of providing the data to the original main.js file.

What am I missing and what is the best practice to handle this?

Thanks