swagger's avatar

Laravel mix_url not working in laravel 7?

I'm trying to set up a CDN for my assets, and according to this I can use mix() to set the CDN with my .env https://laravel.com/docs/7.x/mix#versioning-and-cache-busting

My env: MIX_ASSET_URL="https://somecdn.com"

In the index blade I have but it then request the file at localhost:8080.

What's the issue here?

0 likes
5 replies
swagger's avatar

Solved the problem by looking the the mix() source code. The problem was that I was running it locally in hot environment, so the code look for a /hot folder first, if it exists it will return localhost:8080. By building the frontend for production (npm run build), the url is the correct on.

Now I have a problem with webpack tho, the chunks are still request at the base url instead of the CDN :D any tips?

sidneygijzen's avatar

Did you already add 'mix_url' => env('MIX_ASSET_URL', null) to config/app.php?

swagger's avatar

My webpack.mix.js file:

mix.js('resources/js/app.js', '').vue() .js('resources/js/ads.js', '') .extract([ 'vue', 'jquery', 'bootstrap', 'vue-router', 'vue-meta', 'vue-analytics', ]) .sass('resources/sass/app.scss', 'public/css')

.version();

mix.webpackConfig({

output: { publicPath: "https://mycdn.com/", filename: 'js/main[name].js', chunkFilename: 'js/chunks/[name].js', }, plugins: [ new BundleAnalyzerPlugin(), ], });

The publicPath is not working, the file are request to localhost:8000 instead of mycdn.com

Please or to participate in this conversation.