Created
October 1, 2015 22:32
Revisions
-
jondlm created this gist
Oct 1, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,46 @@ // Make sure you have a `bundle.js` file in the current dir and run this like: // # go run webpack_bundle_analysis.go | sort -n package main import ( "fmt" "io/ioutil" "regexp" "strings" ) func check(e error) { if e != nil { panic(e) } } func main() { re := regexp.MustCompile("[*] [0-9]+ [*]") m := make(map[string]int) dat, err := ioutil.ReadFile("./bundle.js") check(err) lines := strings.Split(string(dat), "\n") cur := "" for _, line := range lines { if re.MatchString(line) { cur = line } else { if _, ok := m[cur]; ok { m[cur] = m[cur] + len(line) } else { m[cur] = 0 } } } total := float64(len(string(dat))) for k, v := range m { fmt.Printf("%d -- %s -- %f%% of total\n", v, k, float64(v)/total*100) } }