
I'm trying to relocate my assets to an 'assets' subfolder inside /public. The mix-manifest.json gets created in the correct location and mix.less() outputs my CSS files and updates the reference in the manifest with the correct location as well. The mix.js() method however behaves strangely, as you can see in the screenshot.
I'm using the simplest possible setup to demonstrate this - a fresh installation of Laravel and npm install. I have tried adding and removing slashes all over the place, but to no avail.
mix.setPublicPath('public/assets');
mix.js('resources/assets/js/index.js', 'js');
mix.less('resources/assets/less/index.less', 'css');
npm run devHmm, strange. I just used your exact setup, and it created public/assets/mix-manifest.json that contains:
{
"/js/app.js": "/js/app.js",
"/css/app.css": "/css/app.css"
}
I have this issue too http://prntscr.com/fr8qqc
mix.setPublicPath(path.join(__dirname, "/dist"))
mix.js('src/assets/js/app.js', 'js')
.extract(['jquery','bootstrap','vue','tether']);
and how i can remove '/' at the beginning of the line
Hey! I'm having some throubles with this too. Actually I have a project from tree weeks ago with last mix version at that moment (0.*) and the public path was working fine. Today I start a new project and I realize that already comes with the Mix 1.1.1.
So, I basically copy / paste my webpack.mix and this issue appears...
My public path is somehing like 'public/assets/www/...' so then I have website folders for css, images, fonts, js etc...
I think I figure it out by using the path.normalize inside setPublicPath like this:
mix.setPublicPath(path.normalize('public/assets/www/'));
but I want to know if now this is the way to use the custom path.
My configuration its actually the same that @omnichronous uses...
Btw, I'm using Windows 10 x64.
I also confirm this on 1.1.1. Thanks for the quick fix @gabrieldasilva
@omnichronous I had the same issue also on a non laravel project I'm using mix on. However, setting the paths like
mix.setResourceRoot(path.normalize('themes/themeName'));
mix.setPublicPath(path.normalize('themes/themeName'));
mix
.js([
'themes/themeName/src/js/app.js'
], 'dist')
.sass('themes/themeName/src/scss/app.scss', 'dist')
.version();
Worked for me.
So now, my manifest,json file looks like this with all the correct file paths
{
"/dist/app.js": "/dist/app.js?id=ca6f22b52a9619b553b2",
"/dist/app.css": "/dist/app.css?id=aee4b6d59927ce2a8b74"
}
when it had the wrong js path previously like so
{
"/themes/eco/dist/app.js ": "/dist/app.js?id=ca6f22b52a9619b553b2",
"/dist/app.css": "/dist/app.css?id=aee4b6d59927ce2a8b74"
}
Just come accross this issue too with version 1.2.2 on a windows machine...
webpack.mix.js
mix.setPublicPath('themes/my-theme')
mix.sass('resources/assets/sass/app.scss', 'assets/css')
.js('resources/assets/js/app.js', 'assets/js')
.options({ processCssUrls: false });
Puts css in..
/themes/my-theme/assets/app.css
Puts js in...
/themes/my-theme/themes/my-theme/assets/js/app.js
If I do path.normalize...
mix.setPublicPath(path.normalize('themes/my-theme'))
Then js is placed in /themes/my-theme/assets/js/app.js
Yeap, this solves the issue on windows paths.
It would be nice to add this to the docs or a quick fix on the core publicPath function. Don麓t know if this is already done
Can confirm that using path.normalize on mix.setPublicPath fixes the issue where I needed to change from:
mix.setPublicPath('../public');
mix.js('resources/assets/js/app.js', '../public/js/app.js'); // or 'js/app.js'
to:
mix.setPublicPath('..\\public');
mix.js('resources/assets/js/app.js', '..\\public/js/app.js'); // or 'js/app.js'
for it to work correctly, or it would freeze at 95% emitting on the npm run development command, and outputs this to the mix-manifest.json:
{
"/E:/projects/test-project/public/E:/projects/test-project/public/js/app.js": "/E:/projects/test-project/public/E:/projects/test-project/public/js/app.js"
}
But adding path.normalize fixes it:
mix.setPublicPath(path.normalize('../public'));
mix.js('resources/assets/js/app.js', '../public/js/app.js'); // or 'js/app.js'
mix-manifest.json:
{
"/js/app.js": "/js/app.js"
}
+1 for this, also works on Mac (macOS Sierra)
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Most helpful comment
Can confirm that using
path.normalizeonmix.setPublicPathfixes the issue where I needed to change from:to:
for it to work correctly, or it would freeze at
95% emittingon thenpm run developmentcommand, and outputs this to the mix-manifest.json:But adding
path.normalizefixes it:mix-manifest.json: