Repository: 11ty/eleventy
Pull request #641 (2019-08-01 23:06:54)

Add addWatchTarget() option to config
I'm trying to move away from build processes tacked onto the front of SSGs. This little helper makes this much easier. It allows you to add a custom watch target so that I can tell eleventy, when my scss or javascript files change, I want you to rebuild the site.

Here's how I use it:

```javascript
// Additional watch targets
config.addWatchTarget('./src/scss/'); 
config.addWatchTarget('./src/js/');
```



Patch:
diff --git a/.github/ISSUE_TEMPLATE/i-have-a-question-about-eleventy.md b/.github/ISSUE_TEMPLATE/i-have-a-question-about-eleventy.md
index d53991f2..04aeed1c 100644
--- a/.github/ISSUE_TEMPLATE/i-have-a-question-about-eleventy.md
+++ b/.github/ISSUE_TEMPLATE/i-have-a-question-about-eleventy.md
@@ -1,10 +1,7 @@
 ---
 name: I have a question about Eleventy
 about: e.g. “How do I do this in Eleventy?” or “Can Eleventy do this?”
-title: ''
+title: ""
 labels: education
-assignees: ''
-
+assignees: ""
 ---
-
-
diff --git a/.github/ISSUE_TEMPLATE/i-m-having-a-problem-with-eleventy.md b/.github/ISSUE_TEMPLATE/i-m-having-a-problem-with-eleventy.md
index 29b3946b..071aead0 100644
--- a/.github/ISSUE_TEMPLATE/i-m-having-a-problem-with-eleventy.md
+++ b/.github/ISSUE_TEMPLATE/i-m-having-a-problem-with-eleventy.md
@@ -1,10 +1,9 @@
 ---
 name: I’m having a problem with Eleventy
 about: Create a report to help us improve
-title: ''
+title: ""
 labels: needs-triage
-assignees: ''
-
+assignees: ""
 ---
 
 **Describe the bug**
@@ -12,6 +11,7 @@ A clear and concise description of what the bug is.
 
 **To Reproduce**
 Steps to reproduce the behavior:
+
 1. Go to '...'
 2. Click on '....'
 3. Scroll down to '....'
@@ -24,8 +24,9 @@ A clear and concise description of what you expected to happen.
 If applicable, add screenshots to help explain your problem.
 
 **Environment:**
- - OS and Version: [e.g. Windows/Mac/Linux]
- - Eleventy Version [via `eleventy --version` or `npx @11ty/eleventy --version`]
+
+- OS and Version: [e.g. Windows/Mac/Linux]
+- Eleventy Version [via `eleventy --version` or `npx @11ty/eleventy --version`]
 
 **Additional context**
 Add any other context about the problem here.
diff --git a/.github/ISSUE_TEMPLATE/i-want-eleventy-do-to-this-new-thing.md b/.github/ISSUE_TEMPLATE/i-want-eleventy-do-to-this-new-thing.md
index 22a1154a..a9928d33 100644
--- a/.github/ISSUE_TEMPLATE/i-want-eleventy-do-to-this-new-thing.md
+++ b/.github/ISSUE_TEMPLATE/i-want-eleventy-do-to-this-new-thing.md
@@ -1,10 +1,9 @@
 ---
 name: I want Eleventy do to this new thing
 about: Suggest an idea for this project
-title: ''
+title: ""
 labels: enhancement
-assignees: ''
-
+assignees: ""
 ---
 
 **Is your feature request related to a problem? Please describe.**
diff --git a/.travis.yml b/.travis.yml
index 4468c9a8..e7614af1 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -13,4 +13,6 @@ sudo: false
 os:
   - linux
   - osx
-  - windows
\ No newline at end of file
+  - windows
+env:
+  - YARN_GPG=no
diff --git a/src/Eleventy.js b/src/Eleventy.js
index e9fa1b06..b0feb717 100644
--- a/src/Eleventy.js
+++ b/src/Eleventy.js
@@ -72,8 +72,7 @@ class Eleventy {
 
     /** @member {Object} - tbd. */
     this.watchTargets = new EleventyWatchTargets();
-
-    /** @member {Object} - tbd. */
+    this.watchTargets.add(this.config.additionalWatchTargets);
     this.watchTargets.watchJavaScriptDependencies = this.config.watchJavaScriptDependencies;
   }
 
diff --git a/src/TemplateConfig.js b/src/TemplateConfig.js
index 903544c4..c8fe5b6c 100644
--- a/src/TemplateConfig.js
+++ b/src/TemplateConfig.js
@@ -3,7 +3,6 @@ const chalk = require("chalk");
 const lodashMerge = require("lodash/merge");
 const TemplatePath = require("./TemplatePath");
 const EleventyBaseError = require("./EleventyBaseError");
-const dependencyTree = require("dependency-tree");
 const eleventyConfig = require("./EleventyConfig");
 const debug = require("debug")("Eleventy:TemplateConfig");
 
diff --git a/src/UserConfig.js b/src/UserConfig.js
index b7e157bc..33ae1d38 100644
--- a/src/UserConfig.js
+++ b/src/UserConfig.js
@@ -55,6 +55,7 @@ class UserConfig {
     // this.userExtensionMap = {};
     // this.templateExtensionAliases = {};
     this.watchJavaScriptDependencies = true;
+    this.additionalWatchTargets = [];
     this.browserSyncConfig = {};
   }
 
@@ -551,6 +552,10 @@ class UserConfig {
   //   this.templateExtensionAliases[extension] = targetKey;
   // }
 
+  addWatchTarget(additionalWatchTargets) {
+    this.additionalWatchTargets.push(additionalWatchTargets);
+  }
+
   setWatchJavaScriptDependencies(watchEnabled) {
     this.watchJavaScriptDependencies = !!watchEnabled;
   }
@@ -596,6 +601,7 @@ class UserConfig {
       experiments: this.experiments,
       // templateExtensionAliases: this.templateExtensionAliases,
       watchJavaScriptDependencies: this.watchJavaScriptDependencies,
+      additionalWatchTargets: this.additionalWatchTargets,
       browserSyncConfig: this.browserSyncConfig,
       frontMatterParsingOptions: this.frontMatterParsingOptions
     };


Test patch:
diff --git a/test/TemplateConfigTest.js b/test/TemplateConfigTest.js
index 8815233c..403b88cd 100644
--- a/test/TemplateConfigTest.js
+++ b/test/TemplateConfigTest.js
@@ -328,3 +328,15 @@ test("Properly throws error when config returns a Promise", t => {
     );
   });
 });
+
+test(".addWatchTarget adds a watch target", t => {
+  eleventyConfig.reset();
+  eleventyConfig.addWatchTarget("/testdirectory/");
+
+  let templateCfg = new TemplateConfig(
+    require("../config.js"),
+    "./test/stubs/config.js"
+  );
+  let cfg = templateCfg.getConfig();
+  t.deepEqual(cfg.additionalWatchTargets, ["/testdirectory/"]);
+});