Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different path for compiled files #7

Open
sebszocinski opened this issue Apr 29, 2018 · 13 comments
Open

Different path for compiled files #7

sebszocinski opened this issue Apr 29, 2018 · 13 comments

Comments

@sebszocinski
Copy link

Hi i'm having some trouble setting this up with different folder paths and sub-directories.

My source structure is like this:

image

And I need my compiled dist structure to look like this:

image

so I need to compile from site_root/source/pug/*/*.pug to site_root/site/themes/rkt/*/*.html

I've tried the following:

   .sass('source/sass/rkt.sass', 'css')
   .pug('source/pug/layouts/*.pug', 'layouts')
   .pug('source/pug/partials/*.pug', 'partials')
   .pug('source/pug/templates/*.pug', 'templates')
   .setPublicPath('site/themes/rkt')
   .browserSync('laravelmix.test');

The CSS and JS compile and move fine... but all three Pug compiles fail with this error:

Error: ENOENT: no such file or directory, open '/Users/seb/Dev/Laravel Mix/laravelmix/source/pug/layouts/layouts/default.html'

So then I tried:

.pug('source/pug/layouts/*.pug', 'site/themes/rkt/layouts', {
	   exludePath: 'source/pug'
   })

and i'm still getting this error:

Pug Compilation Failed!

Error: ENOENT: no such file or directory, open '/Users/seb/Dev/Laravel Mix/laravelmix/source/pug/layouts/site/themes/rkt/layouts/default.ht
ml'
@Fredwared
Copy link

Fredwared commented May 2, 2018

   .pug('src/pug/*.pug', '../../dist',  {   		
	   	pug: {
	        pretty: true,
	        debug: false
	    }
   })
   .setPublicPath('dist');

this works for me

@sebszocinski
Copy link
Author

sebszocinski commented May 3, 2018

Nup doesn't work for me...

I tried this slight variation:

   .pug('source/pug/*/*.pug', '../../dist',  {
   	   	pug: {
   	        pretty: true,
   	        debug: false
   	    }
    })
   .setPublicPath('site/themes/rkt')

and get this error:

Error: ENOENT: no such file or directory, open '/Users/seb/Dev/Laravel Mix/laravelmix/source/dist/home.html'

@sebszocinski
Copy link
Author

It's like its not even obeying this:
.setPublicPath('site/themes/rkt')

@sebszocinski
Copy link
Author

Hmm ok this works:

   .pug('source/pug/*/*.pug', '../../../site/themes/rkt',  {
   	   	pug: {
   	        pretty: true,
   	        debug: false
   	    }
    })
   .setPublicPath('site/themes/rkt')

But it's just putting all the html files inside site/themes/rkt and not in their folders...how do you do that?

@sebszocinski
Copy link
Author

Ok this also works, but isn't ideal... and it seems to be running pug 3 times so compiling is really slow? which seems like its not he right way to do it?

.pug('source/pug/layouts/*.pug', '../../../site/themes/rkt/layouts',  {
        exludePath: 'source/pug/'
})
.pug('source/pug/partials/*.pug', '../../../site/themes/rkt/partials',  {
	exludePath: 'source/pug/'
})
.pug('source/pug/templates/*.pug', '../../../site/themes/rkt/templates',  {
	exludePath: 'source/pug/'
})

@matejsvajger
Copy link
Owner

matejsvajger commented May 3, 2018

Hey, sorry I'm a bit stuffed at the moment with my day job, but I will setup a test case and try to reproduce your problem.

In the mean time, can you try the glob operator ** if it works:

.pug('source/pug/**/*.pug', '../../../site/themes/rkt',  {
        exludePath: 'source/pug/'
})

@sebszocinski
Copy link
Author

sebszocinski commented May 3, 2018 via email

@matthewjumpsoffbuildings

any news on this? i'd like to be able to use pug with mix but this issue is still occuring

@matthewjumpsoffbuildings
Copy link

matthewjumpsoffbuildings commented Jun 20, 2018

@matejsvajger i found a fork that seems to address this issue - https://github.com/rivergod/laravel-mix-pug

have you seen it?

heres the commit in question: rivergod@c5658a2

@matthewjumpsoffbuildings

@matejsvajger @sebszocinski I just tested the @rivergod fork and it seems to work

for example

mix.js('src/js/app.js', 'dist/js')
	.sass('src/sass/app.sass', 'dist/css')
	.pug('src/pug/**/*.pug', 'dist', {
		excludePath: 'src/pug'
	})
	.setPublicPath('dist');

put any folders i had in my src/pug folder into the output dist directory correctly

@juniorgarcia
Copy link

I was having the same problem. After debugging I realized that by now the plugin outputs the compiled files to the relative path we configure to get the templates from. Let's say that the templates are at src/templates/myfile.pug. The output file will be src/template/<my_dist_folder>/myfile.html. Even calling mix.setPublicPath didn't solve the problem form me.

My solution was to calculate the relative from the template filte path to the public folder:

// ...
mix.pug('src/templates/*.pug', path.relative('src/templates', 'dist'), {});
// ...

@matthewjumpsoffbuildings

@juniorgarcia yep that works for me too, cheers

@mikemartin
Copy link

mikemartin commented May 3, 2019

Thanks everyone. I've forked the latest from matejsvajger/laravel-mix-pug and made a pull request #14 with the recursive compiling fix from rivergod@c5658a2.

With this fix I can now compile my entire folder of pug templates:

.pug('_theme/**/*.pug', dist, {
   excludePath: '_theme'
})

In the meantime I've published the fork to NPM as laravel-mix-pug-recursive. (first time publishing an npm package, so please correct me if I went about this the incorrect way)
https://www.npmjs.com/package/laravel-mix-pug-recursive

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants