Skip to content

Commit 97d23ae

Browse files
authored
chore(gatsby): Update documentation around pathPrefix and assetPrefix combination (#34226)
1 parent 6b28b69 commit 97d23ae

File tree

4 files changed

+35
-5
lines changed

4 files changed

+35
-5
lines changed

docs/docs/how-to/previews-deploys-hosting/path-prefix.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,4 @@ For pathnames you construct manually, there’s a helper function, [`withPrefix`
101101

102102
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.
103103

104-
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.
104+
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).

packages/gatsby/index.d.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -946,12 +946,23 @@ export interface ParentSpanPluginArgs extends NodePluginArgs {
946946
export interface NodePluginArgs {
947947
/**
948948
* Use to prefix resources URLs. `pathPrefix` will be either empty string or
949-
* path that starts with slash and doesn't end with slash. Check
950-
* [Adding a Path Prefix](https://www.gatsbyjs.org/docs/path-prefix/)
949+
* path that starts with slash and doesn't end with slash. `pathPrefix` also
950+
* becomes <assetPrefix>/<pathPrefix> when you pass both `assetPrefix` and
951+
* `pathPrefix` in your `gatsby-config.js`.
952+
*
953+
* See [Adding a Path Prefix](https://www.gatsbyjs.com/docs/how-to/previews-deploys-hosting/path-prefix/)
951954
* page for details about path prefixing.
952955
*/
953956
pathPrefix: string
954957

958+
/**
959+
* This is the same as `pathPrefix` passed in `gatsby-config.js`.
960+
* It's an empty string if you don't pass `pathPrefix`.
961+
* When using assetPrefix, you can use this instead of pathPrefix to recieve the string you set in `gatsby-config.js`.
962+
* It won't include the `assetPrefix`.
963+
*/
964+
basePath: string
965+
955966
/**
956967
* Collection of functions used to programmatically modify Gatsby’s internal state.
957968
*/

packages/gatsby/src/utils/api-node-docs.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,13 @@ export const onPreBuild = true
437437
/**
438438
* The last extension point called after all other parts of the build process
439439
* are complete.
440+
*
441+
* @example
442+
* exports.onPostBuild = ({ reporter, basePath, pathPrefix }) => {
443+
* reporter.info(
444+
* `Site was built with basePath: ${basePath} & pathPrefix: ${pathPrefix}`
445+
* );
446+
* };
440447
*/
441448
export const onPostBuild = true
442449

packages/gatsby/src/utils/api-node-helpers-docs.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,21 @@ module.exports.tracing = true;
302302

303303
/**
304304
* Use to prefix resources URLs. `pathPrefix` will be either empty string or
305-
* path that starts with slash and doesn't end with slash. Check
306-
* [Adding a Path Prefix](https://www.gatsbyjs.org/docs/path-prefix/)
305+
* path that starts with slash and doesn't end with slash. `pathPrefix` also
306+
* becomes <assetPrefix>/<pathPrefix> when you pass both `assetPrefix` and
307+
* `pathPrefix` in your `gatsby-config.js`.
308+
*
309+
* See [Adding a Path Prefix](https://www.gatsbyjs.com/docs/how-to/previews-deploys-hosting/path-prefix/)
307310
* page for details about path prefixing.
308311
* @type {string}
309312
*/
310313
module.exports.pathPrefix = true;
314+
315+
/**
316+
* This is the same as `pathPrefix` passed in `gatsby-config.js`.
317+
* It's an empty string if you don't pass `pathPrefix`.
318+
* When using assetPrefix, you can use this instead of pathPrefix to recieve the string you set in `gatsby-config.js`.
319+
* It won't include the `assetPrefix`.
320+
* @type {string}
321+
*/
322+
module.exports.basePath = true;

0 commit comments

Comments
 (0)