This project is read-only.

Support for files that bundle files depend on

Jul 25, 2013 at 6:57 PM
Edited Jul 25, 2013 at 6:57 PM
I was wondering if there could be support for adding files to a bundle that aren't actually rendered in the bundle, but still monitored for changes. While it sounds pointless, it makes sense for some higher level languages like sass.

An example

Lets say I have a sass file app.scss, which has 3 include files - _variables.scss, _mixins.scss, and _normalize.scss. I only add app.scss to the bundle because it is includes the other files and gets compiled to a CSS file.

If I change one of the include files the app.css file should be regenerated but it isn't because they weren't added to the bundle. Right now I work around this problem by just adding everything, which is problematic.

When optimizations are disabled, the bundle will just emit all the files as individual items, which I have a handler for .scss files which processes them individually, but files like _variables.scss are not standalone files, so I just have to emit an empty response.

The solution

Well, this part isn't very easy, as I can't really think of an elegant way to solve this. It could be tackled from a couple of different directions.
  1. Mirror the existing api for adding bundle files. Basically WatchFile / WatchDirectory
  2. Allow bundle transforms to emit a list of files that were used during transformation.
The first method is likely the simplest to implement, but could become too much maintenance (file by file) or become too complicated (multiple bundles but attempting to watch directory) for end users. It would work and could be implemented simply. The multiple bundle problem i eluded to isn't a big problem, it's just that you may have other bundles getting regenerated even if files in them didn't change.

The second method is likely the correct solution, but is likely more difficult to implement. It would solve the example problem I gave, and I can see how it would be applicable to many other scenarios (for example, a transform that embeds images in a css file).

Ultimately, all that is needed is something that allows the bundle to look at other files that aren't passed to bundle transforms that can be used to determine if the bundle is current.