Task: Add app provider and add config alias paths for tsconfig and removed React imported

This commit is contained in:
Sambo Chea 2021-06-12 17:38:19 +07:00
parent 371b4fad15
commit 26451a4291
12 changed files with 40 additions and 15 deletions

View File

@ -7,6 +7,7 @@ CUBETIQ React App Template for general use in react application.
- Create React App: 4.0.3 - Create React App: 4.0.3
- React: 17.0.0 - React: 17.0.0
- TypeScript: 4.1.2 - TypeScript: 4.1.2
- Craco: 6.1.2 | Craco less: 1.17.1
# Contributors # Contributors

View File

@ -1,9 +1,16 @@
const path = require('path') const path = require('path');
module.exports = { module.exports = {
resolve: { webpack: {
alias: { alias: {
'@': path.resolve(__dirname, './src'), '@': path.resolve(__dirname, 'src/')
}, }
}, },
} jest: {
configure: {
moduleNameMapper: {
'^@(.*)$': '<rootDir>/src$1'
}
}
}
};

View File

@ -1,10 +1,10 @@
import React from 'react' import AppProvider from '@/provider/AppProvider'
import RouterView from '../routes' import RouterView from '../routes'
import './App.css' import './App.less'
const App = () => { const App = () => {
return ( return (
<RouterView /> <AppProvider><RouterView /></AppProvider>
) )
} }

View File

@ -1,7 +1,7 @@
import React from 'react' import React from 'react'
import ReactDOM from 'react-dom' import ReactDOM from 'react-dom'
import './index.css' import './index.less'
import App from './app/App' import App from '@/app/App'
import reportWebVitals from './reportWebVitals' import reportWebVitals from './reportWebVitals'
ReactDOM.render( ReactDOM.render(

View File

@ -1,4 +1,3 @@
import React from 'react'
import './index.less' import './index.less'
export default function About() { export default function About() {

View File

@ -1,4 +1,3 @@
import React from 'react'
import './index.less' import './index.less'
export default function Home() { export default function Home() {

View File

@ -0,0 +1,5 @@
const AppProvider = (props: any) => {
return <>{props.children}</>
}
export default AppProvider

View File

@ -1,4 +1,3 @@
import React from 'react'
import { BrowserRouter as Router, Switch, Route } from 'react-router-dom' import { BrowserRouter as Router, Switch, Route } from 'react-router-dom'
import { routes } from './routes' import { routes } from './routes'

View File

@ -1,7 +1,11 @@
{ {
"compilerOptions": { "compilerOptions": {
"target": "es5", "target": "es5",
"lib": ["dom", "dom.iterable", "esnext"], "lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true, "allowJs": true,
"skipLibCheck": true, "skipLibCheck": true,
"esModuleInterop": true, "esModuleInterop": true,
@ -16,5 +20,8 @@
"noEmit": true, "noEmit": true,
"jsx": "react-jsx" "jsx": "react-jsx"
}, },
"include": ["src"] "extends": "./tsconfig.paths.json",
"include": [
"src"
]
} }

8
tsconfig.paths.json Normal file
View File

@ -0,0 +1,8 @@
{
"compilerOptions": {
"baseUrl": "./",
"paths": {
"@/*": ["src/*"]
}
}
}