Skip to content

taikongfeizhu/babel-typescript-react-startkit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Webpack + Babel + TypeScript + React Boilerplate

As of babel@7, now we can handle .ts or .tsx files same as .js or .jsx files like this:

// webpack.config.js

module.exports = {
  resolve: {
    extensions: ['.js', '.jsx', '.ts', '.tsx']
  },
  module: {
    rules: [
      {
        test: [/\.jsx?$/, /\.tsx?$/],
        use: 'babel-loader',
        exclude: /node_modules/
      }
    ]
  }
}

Use babel-loader to /\.tsx?$/ ?!

Yes, babel-loader. See .babelrc:

{
  "presets": [
    "@babel/env",
    "@babel/react",
    "@babel/typescript"
  ]
}

Thanks to @babel/preset-typescript, we can handle /\.tsx?$/ files same as /\.jsx?$/ files :)

How to use

# install dependencies
$ yarn

# start a server (development mode)
# it automatically opens `http://localhost:8080` in your default browser, and you'll see "Babel + TypeScript + React = ❤️"
$ yarn dev

# check your types
$ yarn check-types

# production build
$ yarn build

# start a server (production mode)
$ yarn start

About

babel-typescript-react-startkit

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published