abcnews / aunty

A toolkit for working with ABC News projects
https://www.npmjs.com/package/@abcnews/aunty
MIT License
32 stars 5 forks source link

Multiple static directory support. #187

Closed colingourlay closed 1 year ago

colingourlay commented 1 year ago

This allows the definition of multiple static directories, by setting your aunty config's build->staticDir property to an array of strings.

@thomasbrettell asked for a way to use some static assets while developing locally, but exclude them from versioned production releases. This is also a problem I've tried to hack around in the past (during projects like the Aus Talks data explorer and our COVID charts).

Example usage

A common pattern this would be great for would be serving a local directory of data files during development, but pushing those files to a location under /dat/ on ContentFTP (before publication), and forking which endpoint to reference using the NODE_ENV environment variable.

Assuming you had this file in your project: /data/big-chunk-o-data.csv...

In aunty.config.js:

module.exports = {
  build: {
    staticDir: process.env.NODE_ENV === 'development' ? ['public', 'data'] : 'public'
  }
};

In src/index.js:

const ENDPOINT = process.env.NODE_ENV === 'development' ?
  __webpack_public_path__ :
  "https://www.abc.net.au/dat/news/interactives/project-name/"

fetch(`${ENDPOINT}big-chunk-o-data.csv`).then(...)
colingourlay commented 1 year ago

@drzax aunty config values for build, serve and deploy are long-overdue. I've just added a table of build props, but once this is merged, will also add the other two. I've also removed the usage examples for just build::entry from the docs, now that we're putting definitions all in one place.

colingourlay commented 1 year ago

Ah screw it, there's no time like the present. We now have documentation for all 3 commands' config options.