ES6 import from root

后端 未结 8 1666
别跟我提以往
别跟我提以往 2020-12-08 18:28

I\'m currently playing around with React Native. I\'m trying to structure my app, however it\'s starting to get messy with imports.

--app/
    -- /components         


        
8条回答
  •  天命终不由人
    2020-12-08 19:09

    If you're using Create React App you can add paths.appSrc to resolve.modules in config/webpack.config.dev.js and config/webpack.config.prod.js.

    From:

    resolve: {
        modules: ['node_modules', paths.appNodeModules].concat(...
    

    To:

    resolve: {
        modules: [paths.appSrc, 'node_modules', paths.appNodeModules].concat(...
    

    Your code would then work:

    import Loading from 'components/Loading';
    

提交回复
热议问题