项目根目录文件

package.json

  1. {
  2. "script": {
  3. "translations": "node ./translations.js"
  4. }
  5. }

jsconfig.json

  1. {
  2. "compilerOptions": {
  3. "emitDecoratorMetadata": true,
  4. "experimentalDecorators": true,
  5. "baseUrl": ".",
  6. "paths": { // 路径别名,软连接
  7. "@components": ["./src/components/"],
  8. "@models": ["./src/models/"],
  9. "@routes": ["./src/routes/"],
  10. "@utils": ["./src/utils/"],
  11. "@i18n": ["./src/i18n/"],
  12. },
  13. "target": "ES6",
  14. "module": "commonjs",
  15. "allowSyntheticDefaultImports": true
  16. },
  17. "include": ["src/**/*"],
  18. "exclude": ["node_modules"]
  19. }

tsconfig.json

  1. tsconfig配置参考 https://www.typescriptlang.org/docs/handbook/tsconfig-json.html
    1. {
    2. "include": ["**/*"], // blob 格式
    3. }

eslint配置

  1. 安装 eslint插件 ```jsx “eslint”: “^4.19.1”, “eslint-plugin-import”: “^2.11.0”, “eslint-plugin-react”: “^7.7.0”, “eslint-plugin-react-hooks”: “^1.1.0-alpha.1”, “redbox-react”: “^1.3.6”, “redux-devtools-extension”: “2.13.0”

npm install eslint eslint-plugin-import eslint-plugin-react -D

  1. <a name="0TS7O"></a>
  2. ## translationrc.js
  3. 1. Manage all translations based on the extracted messages of the babel-plugin-react-intl
  4. 2. [https://github.com/GertjanReynaert/react-intl-translations-manager](https://github.com/GertjanReynaert/react-intl-translations-manager)
  5. 3. i18n 多语言
  6. ```jsx
  7. yarn add react-intl --save
  8. yarn add react-intl-translations-manager --dev
  9. // translations.js
  10. const manageTranslations = require('react-intl-translations-manager').default
  11. manageTranslations({
  12. messagesDirectory: 'src/translations/extractedMessages'
  13. translationsDirectory: 'src/translations/',
  14. whitelistsDirectory: 'src/translations/allowList/', // 白名单
  15. languages: ['zh', 'en'],
  16. singleMessagesFile: true,
  17. })
  18. // package.json 使用 npm run translations
  19. {
  20. "script": {
  21. "translations": "node ./translations.js"
  22. }
  23. }