-
Notifications
You must be signed in to change notification settings - Fork 0
Home
caijf edited this page Aug 13, 2024
·
6 revisions
Welcome to the doly-cli wiki!
doly-cli@1.x
不再支持 require
语法引入图片或模块文件,请使用 import
语法替换。
示例如下:
- const { formatMoney } = require('util-helpers');
- const TestImage = require('~/assets/image/test.jpg');
+ import { formatMoney } from 'util-helpers';
+ import TestImage from '~/assets/image/test.jpg';
需要将 doly-cli
升级至 v1.2.1+
。
pnpm add typescript @types/react @types/react-dom @types/react-router-dom -D
根目录添加文件 tsconfig.json
:
{
"exclude": ["dist"],
"compilerOptions": {
"target": "ESNext",
"jsx": "react",
"module": "ESNext",
"lib": ["DOM", "ESNext"],
"sourceMap": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"moduleResolution": "Node",
"resolveJsonModule": true,
"allowJs": true,
"noEmit": true,
"paths": {
"~/*": ["./src/*"]
}
}
}
src
目录下添加文件 typings.d.ts
:
declare module '*.css';
declare module '*.less';
declare module '*.scss';
declare module '*.sass';
declare module '*.svg';
declare module '*.png';
declare module '*.jpg';
declare module '*.jpeg';
declare module '*.gif';
declare module '*.bmp';
完成!🎉🎉🎉
尝试将 src/home/index.js
改为 src/home/index.tsx
,然后测试开发 doly dev
和打包 doly build
。
如果要将入口文件 src/app.js
改为 src/app.tsx
,需要同步修改 doly.config.js
:
entry: {
- [pkg.name]: ["./src/utils/polyfill", "./src/app.js"]
+ [pkg.name]: ["./src/utils/polyfill", "./src/app.tsx"]
},
eslint
pritter
等规范配置可以自主选择更新,或继续使用,影响不大。 .eslintrc
文件后缀调整如下:
- "react/jsx-filename-extension": [1, { "extensions": [".js"] }],
+ "react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx", ".ts", ".tsx"] }],