Replies: 1 comment
-
Using path aliases with react-app-rewired and react-app-rewire-alias is quite easy. Create a new React TypeScript App and follow along.
Create a // config-overrides.js
const {alias} = require('react-app-rewire-alias')
module.exports = function override(config) {
alias({
'@assets' : 'src/assets'
})(config)
return config
} Also edit // package.json
{
"scripts": {
- "start": "react-scripts start",
+ "start": "react-app-rewired start",
- "build": "react-scripts build",
+ "build": "react-app-rewired build",
- "test": "react-scripts test",
+ "test": "react-app-rewired test",
"eject": "react-scripts eject"
},
} For this example, create an // App.tsx
- import logo from './logo.svg';
+ import logo from '@assets/logo.svg'; All Done! This should work. To run your project use
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
there is a repo to recurrent this problem:
https://github.com/NoTalk-ly/create-react-app-path-alias-test
or
https://codesandbox.io/s/dry-snow-sfo15?file=/src/index.tsx.
when npm run start, there is a error after compile:
how can I get the "@src" path alias work ?
Beta Was this translation helpful? Give feedback.
All reactions