// SWC : 主要对标Babel,誓言要代替Babel (据说:转译性能比Babel快20倍)
? Select a variant: › - Use arrow-keys. Return to submit.
TypeScript
❯ TypeScript + SWC
JavaScript
JavaScript + SWC
ReactDOM.createRoot(document.getElementById('root')!).render(
// StrictMode 严格模式
// 1. 检查组件是不是纯函数
// 2. 及早的发现 useEffect 中的错误
// 3. 警告过时的 API 可以用 但是不推荐了
<React.StrictMode>
<Provider store={store}>
<App />
</Provider>
</React.StrictMode>,
)
import { fileURLToPath, URL } from 'node:url'
export default defineConfig({
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
},
},
})
-
- 因为用了 node:url
yarn add -D @types/node
-
- 因为 import xxx from '@/xxx/xxx' 会报错 所以要配置
// tsconfig.json
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
}
}
yarn add vite-plugin-eslint -D
// vite.config.ts
import pluginEslint from 'vite-plugin-eslint'
plugins: [
pluginEslint({
include: ['src/*.tsx', 'src/**/*.tsx', 'src/*.ts', 'src/**/*.ts']
}
)
],
注意 配置完 刷新下浏览器
-
- 文件名定义成 xxx.module.scss
-
- 在组件中引入 import style from './App.module.scss'
-
- 使用
-
- 为了支持.驼峰 需要 vite 中配置
// vite.config.ts
css: {
modules: {
localsConvention: 'camelCase',
},
},
- 使用
// App.module.scss
.app {
height: 100vh;
.app-test {
font-size: 30px;
}
}
// app.tsx
import style from './App.module.scss'
...
<div className={style['app-test']}>123</div>
<div className={style.appTest}>123</div> // 使用驼峰也可以了