项目作者: nimacsoft

项目描述 :
📜 Using TypeScript as Babel Plugin with Razzle
高级语言: JavaScript
项目地址: git://github.com/nimacsoft/razzle-plugin-babel-ts.git
创建时间: 2019-06-13T13:04:41Z
项目社区:https://github.com/nimacsoft/razzle-plugin-babel-ts

开源协议:MIT License

下载


npm version

razzle-plugin-babel-ts

This package contains a plugin for using TypeScript as Babel Plugin with Razzle

Usage in Razzle Projects

  1. yarn add razzle-plugin-babel-ts --dev

create a razzle.config.js file in root directory of project (next to the package.json) and put this content inside it

  1. module.exports = {
  2. plugins: ['babel-ts'],
  3. };

create a .babelrc file in next to the razzle.config.js with this content

  1. {
  2. "presets": ["razzle/babel", "@babel/typescript"]
  3. }

Configure TypeScript

config typescript compiler by creating a .tsconfig file next to the razzle.config.js

  1. {
  2. "compilerOptions": {
  3. "allowSyntheticDefaultImports": true,
  4. "noFallthroughCasesInSwitch": true,
  5. "noUnusedParameters": true,
  6. "noImplicitReturns": true,
  7. "moduleResolution": "node",
  8. "esModuleInterop": true,
  9. "noUnusedLocals": true,
  10. "noImplicitAny": true,
  11. "target": "es5",
  12. "module": "esnext",
  13. "strict": true,
  14. "jsx": "react",
  15. "noResolve": false,
  16. "noEmit": true,
  17. "baseUrl": "./src",
  18. "lib": ["dom", "dom.iterable", "esnext"],
  19. "skipLibCheck": true,
  20. "resolveJsonModule": true,
  21. "isolatedModules": true,
  22. "allowJs": true,
  23. "allowUnreachableCode": false,
  24. "downlevelIteration": true,
  25. "forceConsistentCasingInFileNames": true,
  26. "noImplicitThis": true,
  27. "sourceMap": true,
  28. "pretty": true,
  29. "suppressImplicitAnyIndexErrors": true
  30. },
  31. "rootDirs": ["src"]
  32. }

Run Time Type Checking

Craete a new script in package.json

  1. "type-check": "tsc --watch",

and start by run this command in terminal

  1. yarn type-check