Laravel-mix: Unable to mix output .js file to the parent directory

Created on 26 Sep 2017  路  14Comments  路  Source: JeffreyWay/laravel-mix

  • Laravel Mix Version: 1.4.5
  • Node Version: 8.2.1
  • NPM Version: 5.4.2
  • OS: macOS 10.12.6

I've created a src folder within a WordPress themes directory for all build scripts, node modules, etc (so I can hide it when publishing to the server).

In that folder I have webpack.mix.js:

mix.sass('sass/style.scss', '../style.css')
    .js('js/script.js', '../script.js')

This publishes the style.css in the themes (parent) directory as required, but when I do the same for the script.js file it publishes it in the current src folder but creates a list of all folders from my system Users directory Users/jackbarham/Code/etc/.../etc/theme/src/script.js all the way to the output file.

I've tried altering paths, but I can't get it to work or understand why it's working for CSS but not JS.

Most helpful comment

I did sth like that and it's working.
mix.setPublicPath('../') .js('resources/assets/js/app.js', 'js') .sass('resources/assets/sass/app.scss', 'css');

All 14 comments

Hello,
same issue here.

have you found a sollution yet?

No, I haven't yet. Please let me know if you do.

Can you try

mix.sass('sass/style.scss', './../style.css')
    .js('js/script.js', './../script.js')

Otherwise, you might have to specify the path from root.

I've tried that already and get exactly the same output. CSS is correct but not JS.

As a side note: I was previously using Laravel Elixir (a different package, I know) but that compiled both assets into the correct folder using the same path as above.

Try replacing

.js() with .scripts()

and see if it worked.

Ref: https://laravel.com/docs/5.5/mix#vanilla-js

Yes! That's worked :)

Doesn't seem to work for .copy() though. -.-

I am experiencing the same behaviour. Even though the "chunk name" appears to be correct, the whole destination path gets replicated into the folder where I run the script.

Neither relative or absolute filesystem path fixes the problem for me unfortunately.

However, copy and sass command work as expected.

Same problem here.

I have the same problem - this seems like a good work around for the time being: https://github.com/JeffreyWay/laravel-mix/issues/174#issuecomment-275256893

This worked for me: mix.setPublicPath('../parent-folder/');

I did sth like that and it's working.
mix.setPublicPath('../') .js('resources/assets/js/app.js', 'js') .sass('resources/assets/sass/app.scss', 'css');

thanks @eliamariutti , your solution was the good one for me !

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hasnatbabur picture hasnatbabur  路  3Comments

pixieaka picture pixieaka  路  3Comments

mementoneli picture mementoneli  路  3Comments

jpmurray picture jpmurray  路  3Comments

RomainGoncalves picture RomainGoncalves  路  3Comments