#StackBounty: #laravel #webpack #github-actions #laravel-mix #laravel-vapor Why doesn't Laravel Vapor inject ASSET_URL in my build …

Bounty: 50

I am literally copying what the Laravel Vapor documentation states but to no avail. So to keep it short, I am unable to access the ASSET_URL environment variable that Taylor says is injected during the build step.

Now note, the same environment variable is being injected into the application which is why the assets() and mix() helpers in blade on index.blade.php work just fine. However, my problem is accessing the ASSET_URL inside webpack.mix.js.

This is from my Github action below. You can see that ASSET_URL is empty when logged.

> @ production /github/workspace/.vapor/build/app
> cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js

 DONE  Compiled successfully in 26754ms11:23:07 PM


// To deal with Laravel Vapor
if (mix.inProduction()) {
    const ASSET_URL = process.env.ASSET_URL;
    console.log("ASSET URL IS: " + ASSET_URL);

    mix.webpackConfig(webpack => {
        return {
            plugins: [
                new webpack.DefinePlugin({
                    "process.env.ASSET_PATH": JSON.stringify(ASSET_URL)
            output: {
                publicPath: ASSET_URL

Proposed solutions on Laracasts forums

  1. Paul Marshall suggests that he found a workaround by using window.__ASSET_URL__ = '{{ env('ASSET_URL') }}'; but I do not like that approach, unless its the last resort.
  2. @fylzero suggests that I do MIX_ASSET_URL="${ASSET_URL}" in my environment files to see if Mix can read that. It doesn’t.

Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.