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

Configuration method to manually add watch targets #333

Closed
zachleat opened this issue Dec 6, 2018 · 9 comments
Closed

Configuration method to manually add watch targets #333

zachleat opened this issue Dec 6, 2018 · 9 comments
Milestone

Comments

@zachleat
Copy link
Member

zachleat commented Dec 6, 2018

Strings, globs, etc.

Inspired by #325.

eleventyConfig.watch("**/*.js")
@zachleat zachleat added enhancement needs-votes A feature request on the backlog that needs upvotes or downvotes. Remove this label when resolved. labels Dec 6, 2018
@zachleat
Copy link
Member Author

zachleat commented Dec 6, 2018

This repository is now using lodash style issue management for enhancements. This means enhancement issues will now be closed instead of leaving them open.

The enhancement backlog can be found here: https://github.com/11ty/eleventy/issues?utf8=%E2%9C%93&q=label%3Aneeds-votes+sort%3Areactions-%2B1-desc+

Don’t forget to upvote the top comment with 👍!

@gerwitz
Copy link

gerwitz commented Jan 9, 2019

If I understand correctly, this it the feature I need for my use case: I'm using Sass via a gulp task, and want .scss changes to trigger a build.

Having to explain to designers that some files need a manual update process is not something I look forward to. 😉

@zachleat
Copy link
Member Author

zachleat commented Jan 9, 2019

@gerwitz typically when I’ve seen users integrate grunt or gulp, they call eleventy from grunt/gulp and don’t have a manual update process. Can you elaborate on a limitation preventing you from doing that?

@kleinfreund
Copy link
Contributor

Using Eleventy and Sass together, one has two main options:

  • Use Eleventy as the build tool. Then, adding manual watch targets (e.g. a sass directory) would be necessary to trigger a rebuild when changing the Sass files (that’s also true when using plain CSS). However, Eleventy is not a build tool. For more projects with a more complex build process, this could end up being very complicated.
  • Use a third-party build tool (e.g. gulp, grunt, npm). Then, the tool is responsible for watching for file changes and needs to rebuild Eleventy based on that.

@gerwitz
Copy link

gerwitz commented Jan 10, 2019

Thanks for the perspective correction! I’m new to the JS-outside-a-browser ecosystem and need to take the time to learn Gulp, et al before assuming everything will work like Ruby/Java/ASP/PHP/CGI/whatever…

@jevets
Copy link

jevets commented Feb 23, 2019

I was about to post a plea and some context here begging for this feature sooner than later, but I found an alternative solution (thought it was worth posting for anyone's future reference... and my own).

Try to get your special "watch needy" files somewhere into _includes, and you won't need to eleventyConfig.watch() them (even if you never actually {% include %} them from other templates).


@gerwitz If you put your .sass/.scss files into the _includes directory, Eleventy will automatically rebuild whenever one of the files is changed. (You could @import sass files from the _includes dir.)

In fact any file in _includes triggers a rebuild when changed (while eleventy [--serve] [--watch] is running).

It even works if there are no handlers/processors/etc set up for the file type: i.e. saving _includes/some-wacky-file.fakery will trigger a rebuild.


In my case, I'm using postcss, and I set up a stylesheet.11ty.js JS template file (w/ { permalink: 'postcss-processed-styles.css' }) that does the postcss.process() work.

I really wanted to avoid adding a build system (gulp, webpack), to keep things as simple and lean as possible, and to (attempt to) rely only on 11ty for build if I could get away with it.

My problem was that 11ty wouldn't watch dependent .css files (pulled in via postcss-imports in my postcss files). I'd edit a css partial, then I'd have to either restart eleventy --serve or save stylesheet.11ty.js to force a rebuild.

I didn't want to add the .css files to the templateFormats config, since I don't need those files in the built /_site output. (Adding them to templateFormats felt quite unnecessary just for the sake of getting them watched).

Since you can't require() a plain text (css) file in node.js, it's a no go on leveraging watched javascript dependencies for .css files.

@zachleat zachleat removed the needs-votes A feature request on the backlog that needs upvotes or downvotes. Remove this label when resolved. label Feb 19, 2020
@zachleat zachleat added this to the v0.10.0 milestone Feb 19, 2020
@zachleat
Copy link
Member Author

This shipped with 0.10.0 but was never removed from the Enhancement queue! Thanks @MadeByMike

@zachleat
Copy link
Member Author

@MadeByMike can you confirm that this works with Globs? I don’t see that listed explicitly on the docs https://www.11ty.dev/docs/config/#add-your-own-watch-targets

@rolbr
Copy link

rolbr commented Jun 24, 2020

While I'm not Mike I can confirm this works with globs.

eleventyConfig.addWatchTarget("src/**/*.scss"); successfully triggers a rebuild for all changes to .scss files somewhere in src.

Awesome! 🥳

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

No branches or pull requests

5 participants