Skip to content

Commit

Permalink
chore(gatsby): Update documentation around pathPrefix and assetPrefix…
Browse files Browse the repository at this point in the history
… combination (#34226)
  • Loading branch information
marvinjude committed Dec 9, 2021
1 parent 6b28b69 commit 97d23ae
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/docs/how-to/previews-deploys-hosting/path-prefix.md
Expand Up @@ -101,4 +101,4 @@ For pathnames you construct manually, there’s a helper function, [`withPrefix`

The [`assetPrefix`](/docs/how-to/previews-deploys-hosting/asset-prefix/) feature can be thought of as semi-related to this feature. That feature allows your assets (non-HTML files, e.g. images, JavaScript, etc.) to be hosted on a separate domain, for example a CDN.

This feature works seamlessly with `assetPrefix`. Build out your application with the `--prefix-paths` flag and you'll be well on your way to hosting an application with its assets hosted on a CDN, and its core functionality available behind a path prefix.
This feature works seamlessly with `assetPrefix`. Build out your application with the `--prefix-paths` flag and you'll be well on your way to hosting an application with its assets hosted on a CDN, and its core functionality available behind a path prefix. If you use `assetPrefix`, your `pathPrefix` will be changed to `<assetPrefix>/<pathPrefix>`. If you need to access the same `pathPrefix` as in your `gatsby-config.js`, consider using [`basePath`](/docs/reference/config-files/node-api-helpers/#basePath).
15 changes: 13 additions & 2 deletions packages/gatsby/index.d.ts
Expand Up @@ -946,12 +946,23 @@ export interface ParentSpanPluginArgs extends NodePluginArgs {
export interface NodePluginArgs {
/**
* Use to prefix resources URLs. `pathPrefix` will be either empty string or
* path that starts with slash and doesn't end with slash. Check
* [Adding a Path Prefix](https://www.gatsbyjs.org/docs/path-prefix/)
* path that starts with slash and doesn't end with slash. `pathPrefix` also
* becomes <assetPrefix>/<pathPrefix> when you pass both `assetPrefix` and
* `pathPrefix` in your `gatsby-config.js`.
*
* See [Adding a Path Prefix](https://www.gatsbyjs.com/docs/how-to/previews-deploys-hosting/path-prefix/)
* page for details about path prefixing.
*/
pathPrefix: string

/**
* This is the same as `pathPrefix` passed in `gatsby-config.js`.
* It's an empty string if you don't pass `pathPrefix`.
* When using assetPrefix, you can use this instead of pathPrefix to recieve the string you set in `gatsby-config.js`.
* It won't include the `assetPrefix`.
*/
basePath: string

/**
* Collection of functions used to programmatically modify Gatsby’s internal state.
*/
Expand Down
7 changes: 7 additions & 0 deletions packages/gatsby/src/utils/api-node-docs.ts
Expand Up @@ -437,6 +437,13 @@ export const onPreBuild = true
/**
* The last extension point called after all other parts of the build process
* are complete.
*
* @example
* exports.onPostBuild = ({ reporter, basePath, pathPrefix }) => {
* reporter.info(
* `Site was built with basePath: ${basePath} & pathPrefix: ${pathPrefix}`
* );
* };
*/
export const onPostBuild = true

Expand Down
16 changes: 14 additions & 2 deletions packages/gatsby/src/utils/api-node-helpers-docs.js
Expand Up @@ -302,9 +302,21 @@ module.exports.tracing = true;

/**
* Use to prefix resources URLs. `pathPrefix` will be either empty string or
* path that starts with slash and doesn't end with slash. Check
* [Adding a Path Prefix](https://www.gatsbyjs.org/docs/path-prefix/)
* path that starts with slash and doesn't end with slash. `pathPrefix` also
* becomes <assetPrefix>/<pathPrefix> when you pass both `assetPrefix` and
* `pathPrefix` in your `gatsby-config.js`.
*
* See [Adding a Path Prefix](https://www.gatsbyjs.com/docs/how-to/previews-deploys-hosting/path-prefix/)
* page for details about path prefixing.
* @type {string}
*/
module.exports.pathPrefix = true;

/**
* This is the same as `pathPrefix` passed in `gatsby-config.js`.
* It's an empty string if you don't pass `pathPrefix`.
* When using assetPrefix, you can use this instead of pathPrefix to recieve the string you set in `gatsby-config.js`.
* It won't include the `assetPrefix`.
* @type {string}
*/
module.exports.basePath = true;

0 comments on commit 97d23ae

Please sign in to comment.