Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
38f0ad345b
|
|||
2cd90c7b99
|
|||
332d48dd33
|
|||
0e4c6557ca
|
10
CHANGELOG.md
Normal file
10
CHANGELOG.md
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
# v1.1.0
|
||||||
|
## Added
|
||||||
|
* Ability to specify a prefix to use when outputting files via the OutputDir config property.
|
||||||
|
* Documented all config properties to explain their usage.
|
||||||
|
|
||||||
|
## Changed
|
||||||
|
* If no FilePrefix is specified in the config, files will now be written as (hash).min.(extension) (no `app-` prefix as was hardcoded into previous releases).
|
||||||
|
|
||||||
|
# v1.0.0
|
||||||
|
Initial release
|
@ -35,6 +35,7 @@ func main() {
|
|||||||
},
|
},
|
||||||
Minify: true,
|
Minify: true,
|
||||||
OutputDir: "assets/",
|
OutputDir: "assets/",
|
||||||
|
FilePrefix: "app-",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@ -46,6 +47,7 @@ Config key | Use
|
|||||||
Files | An array of strings representing paths to files you want compiled
|
Files | An array of strings representing paths to files you want compiled
|
||||||
Minify | Bool, optionally minify the files with https://github.com/tdewolff/minify
|
Minify | Bool, optionally minify the files with https://github.com/tdewolff/minify
|
||||||
OutputDir | String, the directory you'd like to write the compiled files to (with trailing slash)
|
OutputDir | String, the directory you'd like to write the compiled files to (with trailing slash)
|
||||||
|
FilePrefix | String, what, if anything, should be prefixed onto the output filenames
|
||||||
|
|
||||||
Note that if an output dir is specified, "css" and "js" subdirectories will be used/created to hold the resulting files. Leaving it blank will cause it to not write any files to disk.
|
Note that if an output dir is specified, "css" and "js" subdirectories will be used/created to hold the resulting files. Leaving it blank will cause it to not write any files to disk.
|
||||||
|
|
||||||
|
10
compile.go
10
compile.go
@ -100,10 +100,14 @@ func finalize(config Config, buf map[FileType]*bytes.Buffer) (map[FileType]*Comp
|
|||||||
}
|
}
|
||||||
|
|
||||||
dir := filepath.Join(config.OutputDir, string(key))
|
dir := filepath.Join(config.OutputDir, string(key))
|
||||||
os.MkdirAll(dir, 0755)
|
if err := os.MkdirAll(dir, 0755); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
destFile := filepath.Join(dir, "app-"+ret[key].Hash+ext)
|
destFile := filepath.Join(dir, config.FilePrefix+ret[key].Hash+ext)
|
||||||
ioutil.WriteFile(destFile, bytes, 0644)
|
if err := ioutil.WriteFile(destFile, bytes, 0644); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
ret[key].OutputPath = destFile
|
ret[key].OutputPath = destFile
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,12 @@ package precompiler
|
|||||||
|
|
||||||
// Config holds information on how to run the compiler
|
// Config holds information on how to run the compiler
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
// Files is a list of files to precompile together
|
||||||
Files []string
|
Files []string
|
||||||
|
// Minify specifies whether minification should happen along with concatenation
|
||||||
Minify bool
|
Minify bool
|
||||||
|
// OutputDir if specified will cause the result to be written to this directory
|
||||||
OutputDir string
|
OutputDir string
|
||||||
|
// FilePrefix is a string that will be prefixed on the files if OutputDir is specified
|
||||||
|
FilePrefix string
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user