preact-compat icon indicating copy to clipboard operation
preact-compat copied to clipboard

Mistake in main docs? Need to remove transform-react-jsx?

Open jmas opened this issue 8 years ago • 2 comments
trafficstars

Hello, started setuping a build process with babel and module-resolver, but it get working only when I remove transform-react-jsx plugin. When it included I got an error that function h is not exists. Maybe you need to remove that plugin from docs, but I can be wrong. Thanks for preact-compat.

{
    // ...
    "plugins": [
        ["transform-react-jsx", { "pragma":"h" }],
        ["module-resolver", {
        "root": ["."],
        "alias": {
            "react": "preact-compat",
            "react-dom": "preact-compat"
        }
        }]
    ],
    "presets": [
        "react"
    ]
    // ...
}

jmas avatar Mar 05 '17 19:03 jmas

Hi @jmas - I think the docs for this must be slightly confusing, we've had a few people end up with that issue. The custom pragma option is actually only for those using preact without preact-compat. If you're wanting to use preact-compat (and refer to things as React in your codebase), you don't need any options at all - the "react" preset is fine.

{
    // ...
    "plugins": [
        ["module-resolver", {
        "root": ["."],
        "alias": {
            "react": "preact-compat",
            "react-dom": "preact-compat"
        }
        }]
    ],
    "presets": [
        "react"
    ]
    // ...
}

Alternatively, you can skip the react preset and just add the JSX plugin:

{
    // ...
    "plugins": [
        ["transform-react-jsx"],
        ["module-resolver", {
        "root": ["."],
        "alias": {
            "react": "preact-compat",
            "react-dom": "preact-compat"
        }
        }]
    ],
    "presets": []
    // ...
}

developit avatar Mar 05 '17 22:03 developit

By the way, if you add me as a contributor on babel-preset-preact I'd be happy to publish a working version! ❤️

developit avatar Mar 05 '17 22:03 developit