Documentation ¶
Overview ¶
Package concatjs provides a simple way of serving JavaScript sources in development.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ServeConcatenatedJS ¶
func ServeConcatenatedJS(manifestPath string, root string, preScripts []string, postScripts []string, fs FileSystem) http.Handler
ServeConcatenatedJS returns an http.Handler that serves the JavaScript files listed in manifestPath in one concatenated, eval separated response body.
This greatly speeds up development load times due to fewer HTTP requests, but still for easy debugging by giving the eval'ed fragments URLs through sourceURL comments.
Example usage:
http.Handle("/app_combined.js", concatjs.ServeConcatenatedJS("my/app/web_srcs.MF", ".", [], [], nil))
Relative paths in the manifest are resolved relative to the path given as root.
Types ¶
type FileCache ¶
type FileCache struct {
// contains filtered or unexported fields
}
FileCache caches a set of files in memory and provides a single method, WriteFiles(), that streams them out in the concatjs format.
func NewFileCache ¶
func NewFileCache(root string, fs FileSystem) *FileCache
NewFileCache constructs a new FileCache. Relative paths in the cache are resolved relative to root. fs injects file system access, and will use the real file system if nil.
type FileSystem ¶
type FileSystem interface { StatMtime(filename string) (time.Time, error) ReadFile(filename string) ([]byte, error) ResolvePath(root string, file string) (string, error) }
FileSystem is the interface to reading files from disk. It's abstracted into an interface to allow tests to replace it.
type RealFileSystem ¶
type RealFileSystem struct{}
RealFileSystem implements FileSystem by actual disk access.
func (*RealFileSystem) ReadFile ¶
func (fs *RealFileSystem) ReadFile(filename string) ([]byte, error)
ReadFile reads the specified file using the real filesystem.
func (*RealFileSystem) ResolvePath ¶
func (fs *RealFileSystem) ResolvePath(root string, file string) (string, error)
ResolvePath resolves the specified path within a given root by joining root and the filepath. This is only works if the specified file is located within the given root in the real filesystem. This does not work in Bazel where requested files aren't always located within the specified root. Files would need to be resolved as runfiles.