All Projects → wub → preact-cli-plugin-typescript

wub / preact-cli-plugin-typescript

Licence: MIT license
Adds TypeScript support to preact-cli ⚡

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to preact-cli-plugin-typescript

preact-cli-plugin-netlify
Preact cli plugin for generating h2push headers and redirects rules for netlify
Stars: ✭ 25 (-48.98%)
Mutual labels:  preact, preact-cli
preact-transitioning
Preact components for easily implementing basic CSS animations and transitions
Stars: ✭ 35 (-28.57%)
Mutual labels:  preact
Preact Worker Demo
Demo of preact rendering an entire app in a Web Worker.
Stars: ✭ 204 (+316.33%)
Mutual labels:  preact
Prefresh
Hot Module Reloading for Preact
Stars: ✭ 247 (+404.08%)
Mutual labels:  preact
Styled Loaders
Loaders Built with Preact and Styled Components
Stars: ✭ 212 (+332.65%)
Mutual labels:  preact
blurhash-as
Blurhash implementation in AssemblyScript
Stars: ✭ 26 (-46.94%)
Mutual labels:  preact
Recal
A minimal, accessible React/Preact calendar component using modern CSS.
Stars: ✭ 191 (+289.8%)
Mutual labels:  preact
xoid
Framework-agnostic state management library designed for simplicity and scalability ⚛
Stars: ✭ 96 (+95.92%)
Mutual labels:  preact
preact-route-async
Easy asynchronous loading for your router components. For 440B.
Stars: ✭ 36 (-26.53%)
Mutual labels:  preact
Rex Tils
Type safe utils for redux actions, epics, effects, react/preact default props, various type guards and TypeScript utils, React util components
Stars: ✭ 245 (+400%)
Mutual labels:  preact
React
MOVED TO https://github.com/myitcv/x/blob/master/react/_doc/README.md
Stars: ✭ 234 (+377.55%)
Mutual labels:  preact
Preact Custom Element
Wrap your component up as a custom element
Stars: ✭ 212 (+332.65%)
Mutual labels:  preact
vitext
The Next.js like React framework for better User & Developer experience!
Stars: ✭ 376 (+667.35%)
Mutual labels:  preact
Preact Devtools
Browser extension for inspection Preact applications
Stars: ✭ 204 (+316.33%)
Mutual labels:  preact
preact-css-transition-group
Apply CSS transitions when adding or removing Preact components/elements
Stars: ✭ 60 (+22.45%)
Mutual labels:  preact
Preact Redux Example
🔁 Preact + Redux Example Project
Stars: ✭ 199 (+306.12%)
Mutual labels:  preact
Facebook Political Ads
Monitoring Facebook Political Ads
Stars: ✭ 215 (+338.78%)
Mutual labels:  preact
preact-cli-sw-precache
Preact cli plugin for configuring sw-precache
Stars: ✭ 19 (-61.22%)
Mutual labels:  preact
preact-wp
No description or website provided.
Stars: ✭ 12 (-75.51%)
Mutual labels:  preact
preact-photon-electron-quick-start
Demo desktop app built with Electron using the Preact-Photon UI library
Stars: ✭ 32 (-34.69%)
Mutual labels:  preact

preact-cli-plugin-typescript · Build status npm version JavaScript Style Guide

Use TypeScript with preact-cli.

This will install typescript and awesome-typescript-loader.

If you prefer Flow, check out preact-cli-plugin-flow.

Installation

Install via npm:

npm i preact-cli-plugin-typescript --save-dev

After installation, this plugin will create a tsconfig.json (TypeScript configuration file), and preact.config.js, if they don't exist already.

In the root of your project, edit preact.config.js to add the plugin:

import preactCliTypeScript from 'preact-cli-plugin-typescript'

export default function(config) {
  preactCliTypeScript(config)
}

Usage

Existing tsconfig.json

If you have an existing tsconfig.json file, be sure to use the correct JSX factory:

{
  "compilerOptions": {
    "jsx": "react",
    "jsxFactory": "h"
  }
}

Now you can simply add .ts/.tsx files to your project, and they'll be compiled. Cool. Make sure you use .tsx if you want to use JSX.

Mixing JavaScript and TypeScript

You might see an error like Module './components/app' was resolved to '/src/components/app.js', but '--allowJs' is not set..

To fix this, or if you want to incrementally move to TypeScript, make sure allowJs is enabled in your tsconfig.json:

{
  "compilerOptions": {
    "allowJs": true
  }
}

Changing the entrypoint

By default, preact-cli looks for src/index.js to start your app. This plugin widens the scope to "any file in src that starts with index and has a file extension resolved by webpack" - to change this, override the preact-cli-entrypoint in preact.config.js:

import { resolve } from 'path'

export default function (config, env, helpers) {
  preactCliTypeScript(config)

  config.resolve.alias['preact-cli-entrypoint'] = resolve(__dirname, 'src', 'foo-file.foo-extension')
}

Changing the entrypoint is NOT fully supported by preact-cli at this time. We recommend enabling allowJs in your tsconfig.json, so that the entrypoint for preact-cli can remain as src/index.js.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].