Skip to content
Permalink
Browse files

Add devAssetsPath and stagingAssetsPath (#1208)

* Add devAssetsPath and stagingAssetsPath

* Update index.d.ts
  • Loading branch information...
kalinchuk authored and sw-yx committed Jul 9, 2019
1 parent b5af6fe commit 9e169e60b1e39a6d276b44862d32b740da11c17e
Showing with 17 additions and 1 deletion.
  1. +10 −0 docs/config.md
  2. +2 −0 packages/react-static/src/index.d.ts
  3. +5 −1 packages/react-static/src/static/getConfig.js
@@ -11,6 +11,8 @@ A `static.config.js` file is optional, but recommended at your project root to u
- [stagingBasePath](#stagingbasepath)
- [devBasePath](#devbasepath)
- [assetsPath](#assetsPath)
- [devAssetsPath](#devassetspath)
- [stagingAssetsPath](#stagingassetspath)
- [extractCssChunks](#extractcsschunks)
- [inlineCss](#inlinecss)
- [Document](#document)
@@ -164,6 +166,14 @@ Works exactly like `basePath`, but only when running the dev server.

Your `assetsPath` determines where your bundled JS and CSS will be loaded from. This is helpful if you want to host your assets in an external location such as a CDN.

### `devAssetsPath`

Works exactly like `assetsPath`, but only when running the dev server.

### `stagingAssetsPath`

Works exactly like `assetsPath`, but only when building with the `--staging` build flag.

### `extractCssChunks`

`extractCssChunks` replaces default `ExtractTextPlugin` with `ExtractCssChunks`. It enables automatic CSS splitting into separate files by routes as well as dynamic components (using `react-universal-component`). More information about the [plugin](https://github.com/faceyspacey/extract-css-chunks-webpack-plugin) and [why it is useful as a part of CSS delivery optimisation](https://github.com/faceyspacey/extract-css-chunks-webpack-plugin#what-about-glamorous-styled-components-styled-jsx-aphrodite-etc). Defaults to `false`.
@@ -37,6 +37,8 @@ declare module 'react-static' {
stagingBasePath?: string
devBasePath?: string
assetsPath?: string
stagingAssetsPath?: string
devAssetsPath?: string
extractCssChunks?: boolean
inlineCss?: boolean
disablePreload?: boolean
@@ -121,17 +121,21 @@ export function buildConfig(state, config = {}) {
// siteRoot, basePath, publicPath, and assetPath resolution
let siteRoot = ''
let basePath = ''
let assetsPath = ''
if (process.env.REACT_STATIC_ENV === 'development') {
basePath = cleanSlashes(config.devBasePath)
assetsPath = config.devAssetsPath || paths.assets
} else if (state.staging) {
siteRoot = cutPathToRoot(config.stagingSiteRoot || '/', '$1')
basePath = cleanSlashes(config.stagingBasePath)
assetsPath = config.stagingAssetsPath || paths.assets
} else {
siteRoot = cutPathToRoot(config.siteRoot, '$1')
basePath = cleanSlashes(config.basePath)
assetsPath = config.assetsPath || paths.assets
}
const publicPath = `${cleanSlashes(`${siteRoot}/${basePath}`)}/`
let assetsPath = config.assetsPath || paths.assets || ''

if (assetsPath && !isAbsoluteUrl(assetsPath)) {
assetsPath = `/${cleanSlashes(`${basePath}/${assetsPath}`)}/`
}

0 comments on commit 9e169e6

Please sign in to comment.
You can’t perform that action at this time.