3 A basic skeleton web application server. Just add HTML, client-side JavaScript code, and server-side APIs.
6 * In development, use npm to install JavaScript libraries.
7 * At build time, use webpack on nodejs to compile JavaScript assets.
8 * Deploy with a single Go binary -- no nodejs, no asset files.
10 ## dev/build dependencies
15 curl https://storage.googleapis.com/golang/go1.7.4.linux-amd64.tar.gz \
16 | sudo tar -C /usr/local -xzf - \
17 && (cd /usr/local/bin && sudo ln -s ../go/bin/* .)
23 curl -sL https://deb.nodesource.com/setup_6.x | sudo bash -
24 sudo apt-get install nodejs
27 ## add/edit static files
29 Everything in the `static` directory will be served at `/`.
32 echo foo > static/foo.txt
33 # http://webapp/foo.txt
36 ## add/edit javascript files
38 A webpack will be built using the entry point `js/index.js`, and served at `/js.js`.
41 echo 'function foo() { console.log("foo") }' > js/foo.js
42 echo 'require("./foo"); foo()' > js/index.js
45 The default entry point and published location can be changed by editing `webpack.config.js`. For example, to build separate packs from `js/` and `js-admin/` source directories and serve them at `/user.js` and `/admin.js`:
56 ## generate before commit
58 To make your project `go get`able, run `go generate` before committing. This updates `bindata_assetfs.go`. Consider doing this in `.git/hooks/pre-commit` in case you forget.
60 If you don't need `go get` to work, and you prefer to keep generated files out of your source tree, you can:
63 git rm bindata_assetfs.go
64 echo bindata_assetfs.go >>.gitignore
66 git commit -m 'remove generated data'
69 In this case, your build pipeline must run `go generate` before `go build`.
71 ## run dev-mode server
73 This runs webpack, updates bindata_assetfs.go with the new filesystem, builds a new Go binary, and runs it:
79 To use a port other than the default 8000:
85 In dev mode, source maps are served, and JS is not minified.
87 After changing any source code (including static content), `^C` and run `npm run dev` again.
91 Use nodejs to run JavaScript unit tests in `js/**/*_test.js` (see `js/example_test.js`).
97 Run Go tests the usual way.
103 ## build production-mode server
109 The server binary will be installed to `$GOPATH/bin/`.
111 ## build & run production-mode server
119 * live dev mode with fsnotify and `webpack --watch -d`