Closed arxpoetica closed 7 years ago
Some shell magic can go a long way :)
for f in source/*.pug; do echo 'include /pug/helpers/mixins' | cat - $f | pug --filename $f -b $PWD; done
EDIT: you can also use find
and xargs
, though since the find
regex is a bit weird IMO I used globs above instead.
That's some sweet bash logix above. I was trying to do something similar, but my shell chops aren't up to snuff. Thx for the help. ;)
What if I wanted to include (this is a little more complicated) some files (note the plural) like mixins, vars, etc...how could I preload that for each separate file?
I think this isn't a common use case, but I'm compiling multiple pug files SEPARATE of one another, but I want to include lots of files without manually doing it at the top of each file. (I can always just be manual, too...but who wants to do THAT :P )
You can have a common include
//- /pug/mixins-and-vars.pug
include /pug/mixins/a.pug
include /pug/mixins/b.pug
include /pug/mixins/c.pug
include /pug/mixins/d.pug
include /pug/vars/a.pug
include /pug/vars/b.pug
include /pug/vars/c.pug
Generally though I'd recommend just write them manually, for the same reason why modular JS is better than dumping everything to window
or globals
.
I'm using npm (actually yarn) scripts, and would like to prepend a file of mixins to a series of pug files in a directory. I could just manually
include
in each file, but I'd rather automate this if possible.I tried the following (for example), but it's not working as expected:
Any ideas?