graphpack icon indicating copy to clipboard operation
graphpack copied to clipboard

Flow support

Open mxstbr opened this issue 6 years ago • 5 comments

I see that graphpack supports TypeScript out of the box (#12), how about Flowtype? Would that only require adding a custom Babel configuration?

mxstbr avatar Nov 07 '18 08:11 mxstbr

Yep I would say so. Add your .flowconfig and:

// babel.config.js
module.exports = {
  presets: ['graphpack/babel', '@babel/preset-flow'],
};

glennreyes avatar Nov 07 '18 10:11 glennreyes

Can I somehow remove the built-in TypeScript support from graphpack/babel? I don't want that to accidentally interfere with any of the flow typings.

mxstbr avatar Nov 07 '18 10:11 mxstbr

Oh good point! Well, since there's not much in graphpack/babel, you could just use what's in there and remove the TS preset:

// babel.config.js
module.exports = {
  plugins: ['@babel/plugin-syntax-dynamic-import'],
  presets: [
    ['@babel/preset-env', { targets: { node: 'current' }, modules: false }],
    '@babel/preset-flow',
  ],
};

glennreyes avatar Nov 07 '18 10:11 glennreyes

I see, makes sense! Maybe it's worth making that an option?

module.exports = {
  presets: [
    [['graphpack/babel', { types: 'flow' | 'typescript' | false }]],
};

mxstbr avatar Nov 07 '18 10:11 mxstbr

Ideally, Graphpack can detect whether there's a .flowconfig or tsconfig.json and adds babel presets accordingly. This way we wouldn't have to deal with babel config at all.

glennreyes avatar Nov 07 '18 11:11 glennreyes