Automate Asset Compilation in WebStorm with File Watchers
WebStorm’s File Watchers let you automatically compile Sass, TypeScript, or any CLI tool on every file save. Learn how to set up a built‑in Sass watcher, create a custom shell script watcher, and avoid common pitfalls like high CPU usage or duplicate outputs.
17 Aug 2026, 19:55 UTC

Why File Watchers Matter in a Front‑End Workflow
When you’re building a web app you often write source files in a language that compiles to something browsers understand – Sass → CSS, TypeScript → JavaScript, or even a custom build step that bundles assets. Traditionally you’d run a compiler from the command line or a separate IDE each time you change a file. That extra step breaks the flow, introduces latency, and can make the build output inconsistent if you forget to run the command.
WebStorm’s File Watchers solve this by watching a directory for changes and automatically invoking an external tool whenever a file matches a pattern. The tool’s output appears in the IDE console, and any errors surface directly in the editor. The result is a single‑window experience where you edit, save, and instantly see the compiled asset appear.
Setting Up a Built‑In Sass Watcher
1. Open the Watcher dialog. In the main menu choose File → Settings → Tools → File Watchers (or WebStorm → Preferences → Tools → File Watchers on macOS). Click the + button and select Sass → CSS from the template list.
2. Configure the pattern. By default the watcher uses **/*.scss to match all Sass files. If your project uses src/styles/**/*.sass, adjust the File type and Scope fields accordingly.
3. Set the output path. In the Output paths to refresh field, point to the directory where the compiled CSS should live, e.g. public/css. WebStorm will create the file if it doesn’t exist.
4. Save and test. Create a file src/styles/main.scss with the following content:
$primary: #3498db;
body {
background: $primary;
}
Save the file. In the project view you should see public/css/main.css appear automatically. Open the CSS file to confirm the compiled output:
body{background:#3498db}
Custom Watcher: A Generic Shell Script
Built‑in templates cover most common tools, but you can also run any CLI or script. Suppose you want a watcher that simply logs the name of every file you edit. Create a file scripts/echo.sh:
#!/usr/bin/env bash
# echo.sh – simple demo watcher
# $1 is the path of the changed file
printf "File changed: %s\n" "$1"
Make it executable: chmod +x scripts/echo.sh.
Now add a new watcher:
- File type: Custom
- Scope: Project Files
- Program:
$ProjectFileDir$/scripts/echo.sh - Arguments:
$FilePath$ - Output paths to refresh: leave blank (no output file)
Save the watcher. Edit any file in the project, e.g. index.html. The console will show:
File changed: /path/to/project/index.html
Because the script prints to stdout, WebStorm captures that output in the Run tool window. No external terminal is needed.
Trade‑Offs and Practical Limits
- CPU & I/O load: Watching a large directory or running a heavy compiler on every save can spike CPU usage. If you notice sluggishness, narrow the scope or use the
Trigger the watcher on changesoption to limit it to specific file types. - Duplicate or stale files: Some watchers overwrite the same output file on every run. If you have multiple watchers targeting the same output, you may end up with race conditions or duplicated content. Keep a single watcher per output path or use a build tool that handles incremental builds.
- Error handling: Errors from the external tool appear in the console, but the watcher itself doesn’t stop the IDE. For critical errors you may want to add a
Fail on errorflag or integrate with a linter that can block commits.
Actionable Checklist
- Identify the pre‑processor or build step you use most frequently.
- Choose a built‑in watcher template or create a custom one.
- Configure the file pattern, scope, and output path carefully.
- Test by editing a source file and verifying the compiled asset appears.
- Monitor resource usage; if the watcher slows down your machine, narrow the scope or disable it temporarily.
- Commit the watcher configuration to the project’s
.ideadirectory or export it viaFile → Manage IDE Settings → Export Settingsso teammates have the same setup.
With File Watchers, the repetitive act of compiling assets becomes invisible. You can focus on writing code, and the IDE takes care of keeping the browser‑ready files in sync.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.