Reputation: 53
I have a react application, with custom webpack config (webpack-encore).
How can I set 'src' folder as resource root.
Ex:
I want to use
import 'components/someComponent.jsx'
instead of
import '../../components/someComponent.jsx'
Folder structure:
Upvotes: 5
Views: 3767
Reputation: 68
All you have to do is adding like this in webpack config.
module.exports = {
// ...
resolve: {
modules: [path.resolve(__dirname, 'app/src')]
}
}
Upvotes: 4
Reputation: 22875
You can create some alias and then use a shorter path
let config = Encore.getWebpackConfig();
config.resolve.alias["~"] = path.resolve(__dirname, 'app/src');
module.exports = config;
Now your import will look like
import SomeComponent from '~/components/someComponent.jsx'
Upvotes: 1