pars0097's avatar

mix doesn't respect mix_url

In a Laravel 9 project, my CSS/JS files are inside public/assets, something like this:

project-root
--public
----assets
------css
--------style1.css
--------style2.css

I tried to make mix to load css and js files from there. I've added MIX_ASSET_URL=htt p://localhost:8000/assets to .env, and 'mix_url' => env('MIX_ASSET_URL', null) to config/app.php. Here is my webpack.mix.js

const mix = require('laravel-mix');
const path = require('path');
const { glb } = require('laravel-mix-glob'); // Make it always the last extension

mix.setResourceRoot('../')
mix.setPublicPath('public/assets')

mix
    .js('resources/js/common.js', 'js')

    .scripts([
        'resources/js/single-product.js',
        'resources/f    ront-libs/lightboxed/lightboxed.js',
    ], 'public/assets/js/single-product.js')


    .sass(glb.src('resources/sass/**/*.scss'), 'css')

    .styles([
        'resources/front-libs/lightboxed/lightboxed.css',
        'resources/front-libs/xzoom/xzoom.css',
    ], 'public/assets/css/single-product.css')

mix.postCss(
    glb.src('./resources/front-libs/**/*.css'),
    glb.out({
        baseMap: './resources/front-libs',
        outMap: './public/assets/front-libs',
    }),

).options({
    processCssUrls: false
});

mix.js(
    glb.src('./resources/front-libs/**/*.js'),
    glb.out({
        baseMap: './resources/front-libs',
        outMap: './public/assets/front-libs',
        specifier: 'compile',
    })
);
mix.copy('public/assets/mix-manifest.json', 'public/mix-manifest.json');

Now, when I use {{ mix('css/dashboard.css') }} in a blade file, I expect mix to load CSS from h ttp://localhost:8000/assets/css/dashboard.css but it try to load style from h ttp://localhost:8000/css/dashboard.css

P.S: I used te exact same configuration for a laravel 10 project and it works fine.

P.S 2: when I pressed post button I got "Recaptcha failed. Please try again." error, that's why I added space in htt p

0 likes
0 replies

Please or to participate in this conversation.