Skip to content

Commit

Permalink
feat(gatsby-cli): support for PREFIX_PATHS env variable (#21627)
Browse files Browse the repository at this point in the history
Co-authored-by: Ward Peeters <ward@coding-tech.com>
  • Loading branch information
benrobertsonio and wardpeet authored Feb 24, 2020
1 parent b51d187 commit 7bc2c3b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
28 changes: 16 additions & 12 deletions packages/gatsby-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,25 +94,29 @@ At the root of a Gatsby app run `gatsby build` to do a production build of a sit
#### Options
| Option | Description | Default |
| :--------------------------: | ---------------------------------------------------------------------------------------------------------- | :-----: |
| `--prefix-paths` | Build site with link paths prefixed (set pathPrefix in your config) | `false` |
| `--no-uglify` | Build site without uglifying JS bundles (for debugging) | `false` |
| `--open-tracing-config-file` | Tracer configuration file (OpenTracing compatible). See https://www.gatsbyjs.org/docs/performance-tracing/ | |
| `--no-color`, `--no-colors` | Disables colored terminal output | `false` |
| Option | Description | Default |
| :--------------------------: | ---------------------------------------------------------------------------------------------------------- | :---------------------------: |
| `--prefix-paths` | Build site with link paths prefixed (set pathPrefix in your config) | `env.PREFIX_PATHS` or `false` |
| `--no-uglify` | Build site without uglifying JS bundles (for debugging) | `false` |
| `--open-tracing-config-file` | Tracer configuration file (OpenTracing compatible). See https://www.gatsbyjs.org/docs/performance-tracing/ | |
| `--no-color`, `--no-colors` | Disables colored terminal output | `false` |
For prefixing paths, most will want to use the CLI flag (`gatsby build --prefix-paths`). For environments where you can't pass the --prefix-paths flag (ie Gatsby Cloud) this provides another way to prefix paths.
### `serve`
At the root of a Gatsby app run `gatsby serve` to serve the production build of the site
#### Options
| Option | Description |
| :--------------: | ---------------------------------------------------------------------------------------- |
| `-H`, `--host` | Set host. Defaults to localhost |
| `-p`, `--port` | Set port. Defaults to 9000 |
| `-o`, `--open` | Open the site in your (default) browser for you |
| `--prefix-paths` | Serve site with link paths prefixed (if built with pathPrefix in your gatsby-config.js). |
| Option | Description | Default |
| :--------------: | ---------------------------------------------------------------------------------------- | :---------------------------: |
| `-H`, `--host` | Set host. Defaults to localhost | |
| `-p`, `--port` | Set port. Defaults to 9000 | |
| `-o`, `--open` | Open the site in your (default) browser for you | |
| `--prefix-paths` | Serve site with link paths prefixed (if built with pathPrefix in your gatsby-config.js). | `env.PREFIX_PATHS` or `false` |
For prefixing paths, most will want to use the CLI flag (`gatsby build --prefix-paths`). For environments where you can't pass the --prefix-paths flag this provides another way to prefix paths.
### `clean`
Expand Down
12 changes: 8 additions & 4 deletions packages/gatsby-cli/src/create-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,10 @@ function buildLocalCommands(cli, isLocalSite) {
builder: _ =>
_.option(`prefix-paths`, {
type: `boolean`,
default: false,
describe: `Build site with link paths prefixed (set pathPrefix in your gatsby-config.js).`,
default:
process.env.PREFIX_PATHS === `true` ||
process.env.PREFIX_PATHS === `1`,
describe: `Build site with link paths prefixed with the pathPrefix value in gatsby-config.js. Default is env.PREFIX_PATHS or false.`,
})
.option(`no-uglify`, {
type: `boolean`,
Expand Down Expand Up @@ -209,8 +211,10 @@ function buildLocalCommands(cli, isLocalSite) {
})
.option(`prefix-paths`, {
type: `boolean`,
default: false,
describe: `Serve site with link paths prefixed (if built with pathPrefix in your gatsby-config.js).`,
default:
process.env.PREFIX_PATHS === `true` ||
process.env.PREFIX_PATHS === `1`,
describe: `Serve site with link paths prefixed with the pathPrefix value in gatsby-config.js.Default is env.PREFIX_PATHS or false.`,
}),

handler: getCommandHandler(`serve`),
Expand Down

0 comments on commit 7bc2c3b

Please sign in to comment.