Laravel-mix: Issue with output paths when combining setPublicPath & setResourcePath

Created on 31 Aug 2017  路  1Comment  路  Source: JeffreyWay/laravel-mix

  • Laravel Mix Version: 1.4.2
  • Node Version (node -v): 8.4.0
  • NPM Version (npm -v): 5.2.0
  • yarn Version: 0.27.5
  • OS: Windows 10

Description:

Output paths incorrect

Steps To Reproduce:

folder structure

  • /webpack.mix.js
  • /themes/default/dev/js/main.js
  • /themes/default/dev/scss/main.scss
  • /themes/default/dev/svg/**.svg

I would like all dist files to be placed in themes/default/dist/ ideally in js, css, images, fonts subfolders.

webpack.mix.js

mix.setPublicPath('./themes/default/dist/');
mix.setResourceRoot('/themes/default/dist/');

mix.js('./themes/default/dev/js/main.js', 'js');
mix.css('./themes/default/dev/scss/styles.scss', 'css');

styles.scss
contains

.class {
background-image: url('../svg/background-image.svg');
}

This results in the following output

  • /themes/default/dist/css/styles.css
  • /themes/default/dist/fonts/ (with the .svg)
  • /themes/default/dist/themes/default/dist/js/main.js
  • /themes/default/dist/manifest-mix.json - contents below
{ 
    "/themes/default/dist/js/main.js": "/themes/default/dist/js/main.js", 
    "/css/styles.css": "/css/styles.css"
}

So the JS files are being output in the incorrect folder structure.

I have tried;

  1. removing setResourceRoot - svgs still output in the same place but incorrect path in css file
  2. setting public path to ./ and updating dist paths in mix.js() / mix.css() to include the full output path this results in the svg path in styles.css being /themes/default/dist/fonts/background-image.svg but the file located /fonts/background-image.svg - but the javascript now outputs to the correct path.

Happy to try out other configurations / run tests

Most helpful comment

I've managed to have made some progress on this, it looks as though there is a issue with Windows paths

new webpack.mix.js

mix.setPublicPath('themes\\default\\dist');
mix.setResourceRoot('/themes/default/dist/');

mix.js('./themes/default/dev/js/main.js', 'js\\main.js');
mix.css('./themes/default/dev/scss/styles.scss', 'css\\styles.css');

This results in the correct file structure and css url() asset paths

>All comments

I've managed to have made some progress on this, it looks as though there is a issue with Windows paths

new webpack.mix.js

mix.setPublicPath('themes\\default\\dist');
mix.setResourceRoot('/themes/default/dist/');

mix.js('./themes/default/dev/js/main.js', 'js\\main.js');
mix.css('./themes/default/dev/scss/styles.scss', 'css\\styles.css');

This results in the correct file structure and css url() asset paths

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ThomHurks picture ThomHurks  路  38Comments

SethTompkins picture SethTompkins  路  54Comments

mohitpanjwani picture mohitpanjwani  路  36Comments

ghost picture ghost  路  34Comments

KKSzymanowski picture KKSzymanowski  路  36Comments