preactjs / preact-compat

ATTENTION: The React compatibility layer for Preact has moved to the main preact repo.
http://npm.im/preact-compat
MIT License
950 stars 148 forks source link

fix for tsx annoyance #517

Open jeremy-coleman opened 5 years ago

jeremy-coleman commented 5 years ago

any better solution than this?lol

var gulp = require('gulp');
var replace = require('gulp-batch-replace');
var rename = require('gulp-rename')

let t1 = "= preact"
let t2 = "namespace preact"
let r1 = "= React"
let r2 = "namespace React"

var replacements = [
    [ t1, r1 ],
    [ t2, r2]
]

gulp.task('setup', () => {
        return gulp.src('node_modules/preact/src/preact.d.ts')
        .pipe(replace(replacements))
        .pipe(rename('index.d.ts'))
        .pipe(gulp.dest('node_modules/@types/react'))
});
azizhk commented 5 years ago

One more method can be to add aliases in your tsconfig.json

{
  "compilerOptions": {
    "paths": {
      "react": ["preact-compact"],
      "react-dom": ["preact-compact"]
    }
  }
}

You would have to alias the same in your build tools as well. (Webpack etc.)