ES6 import from root

后端 未结 8 1689
别跟我提以往
别跟我提以往 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:05

    Had the same issue with React. So i wrote some plugin for babel which make it possible to import the modules from the root perspective - the paths are not shorter - but it's clear what you import.

    So instead of:

    import 'foo' from '../../../components/foo.js';
    

    You can use:

    import 'foo' from '~/components/foo.js';
    

    Here is the Plugin (tested and with a clear README)

提交回复
热议问题