doczjs / docz

✍ It has never been so easy to document your things!
https://docz.site
MIT License
23.66k stars 1.46k forks source link

tsx support #19

Closed FlatMapIO closed 6 years ago

FlatMapIO commented 6 years ago

My project created by create-react-app-typescript. I tried to import .tsx component but got 'This relative module was not found' message. Is the usage incorrect or is it not yet supported?

pedronauck commented 6 years ago

Did you put the .tsx extension at import?

import { Something } from './Something.tsx'`

I don't even know why this is mandatory on mdx 😞

FlatMapIO commented 6 years ago

Thanks @pedronauck , I tried it and got "Module parse failed: Unexpected token (3:21) You may need an appropriate loader to handle this file type." message

albinekb commented 6 years ago

You need to enable typescript via CLI --typescript or your docz config file.

FlatMapIO commented 6 years ago

docz using babel7 compile tsx, It does not support const enum , So i can't use it for now . Thanks @albinekb .

pedronauck commented 6 years ago

You can modify your bundler config to use ts-loader instead of babel plugin @huodon

export default {
  modifyBundlerConfig: (config) => {
    /* set ts-loader here */
    return config
  }
}
FlatMapIO commented 6 years ago

Thank you @pedronauck , the problem was solved. 👍

cvle commented 6 years ago

@huodon How did you use ts-loader instead? I tried and I failed. Mind showing the essential parts of your config?

pedronauck commented 6 years ago

@cvle if you want to use ts-loader you can just docz-plugin-babel6 that implements ts-loader together with babel 6 ✌️

mbrn commented 6 years ago

if i want to use ts-loader with options: transpileOnly, how can i implement this to doczrc.js

pedronauck commented 6 years ago

If you want to transpile Typescript on our project just pass a config on your doczrc.js:

// doczrc.js
export default {
  typescript: true
}

So, if you want some custom config do something like we did on docz-plugin-babel6 @mbrn https://github.com/pedronauck/docz/blob/master/packages/docz-plugin-babel6/src/index.ts