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
ASSET URL IS:
DONE Compiled successfully in 26754ms11:23:07 PM
webpack.mix.js.
// 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
- 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. - @fylzero suggests that I do
MIX_ASSET_URL="${ASSET_URL}"
in my environment files to see if Mix can read that. It doesn't.