Skip to content

Commit

Permalink
README: Suggest working with Go packages by default.
Browse files Browse the repository at this point in the history
When writing Go code that is something more than just a very short snippet, it helps to organize code as a Go package. It may contain 1 or more .go files in a directory.

`go build` is primarily used with Go packages, as in `go build import/path`. We should suggest the same use of `gopherjs build`. That will make it easier for users to get started and grow their code, because they'll be able to split into multiple .go files without having to update their build step.
  • Loading branch information
dmitshur committed Oct 18, 2015
1 parent d881836 commit 1e66ca3
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -15,7 +15,7 @@ Get or update GopherJS and dependencies with:
go get -u github.com/gopherjs/gopherjs
```

Now you can use `gopherjs build [files]` or `gopherjs install [package]` which behave similar to the `go` tool. For `main` packages, these commands create a `.js` file and `.js.map` source map in the current directory or in `$GOPATH/bin`. The generated JavaScript file can be used as usual in a website. Use `gopherjs help [command]` to get a list of possible command line flags, e.g. for minification and automatically watching for changes. If you want to run the generated code with Node.js, see [this page](https://github.com/gopherjs/gopherjs/blob/master/doc/syscalls.md).
Now you can use `gopherjs build [package]` or `gopherjs install [package]` which behave similar to the `go` tool. For `main` packages, these commands create a `.js` file and `.js.map` source map in the current directory or in `$GOPATH/bin`. The generated JavaScript file can be used as usual in a website. Use `gopherjs help [command]` to get a list of possible command line flags, e.g. for minification and automatically watching for changes. If you want to run the generated code with Node.js, see [this page](https://github.com/gopherjs/gopherjs/blob/master/doc/syscalls.md).

*Note: GopherJS will try to write compiled object files of the core packages to your $GOROOT/pkg directory. If that fails, it will fall back to $GOPATH/pkg.*

Expand Down

4 comments on commit 1e66ca3

@flimzy
Copy link
Member

@flimzy flimzy commented on 1e66ca3 Oct 19, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth mentioning here that import paths relative to . are unsupported (per #148, #302)?

@dmitshur
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I kinda forgot about that. Thanks for bringing it up. I almost never use the raw gopherjs build, instead I'm typically either using gopherjs serve for prototyping or gopherjs_http.NewFS for production use.

However, just gopherjs build works to build the package in the current directory. I think fixing relative import paths may not be that hard and higher priority, so I'll take a look at tackling that.

@neelance
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixing relative import paths for the CLI should be easy. Fixing them for import statements is more complicated.

@dmitshur
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's very little need to fix them for import statement. Not much high quality Go code does that.

Please sign in to comment.