Supercharge your Poi config file with TypeScript

EGOIST
EGOIST
Jan 8, 2018 · 1 min read

Poi maintains a sane list of options to let you customize it, however it might still be painful to remember those options if you’re new to Poi.

So the solution is, you can already tell by the title, TypeScript to the Rescue.

TypeScript VSCode intellisense

It’s really easy to use TypeScript to write Poi config, simply use poi.config.ts instead of poi.config.js :

// Require `poi^9.6.11`
import { Options } from 'poi'
const options: Options = {
entry: 'src/index.js'
}
export default options

To use the file, run:

poi --require ts-node/register --config poi.config.ts

Poi by default doesn’t understand what .ts file is, that’s why you require ts-node here to transform TypeScript to JavaScript.


If you want type-checking in poi.config.js instead of .ts file, you can require babel-register and use corresponding presets instead since you only need to transform ES modules:

// @ts-check
import
{ Options } from 'poi'
/** @type {Options} */
const options = {
entry: 'src/index.js'
}
export default options

EGOIST

Written by

EGOIST

I am GOD’S CHILD.

Poi - delightful web development

Making web app in a delightful way.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade