faceyspacey / babel-plugin-universal-import

🍾 universal(props => import(`./${props.page}`)) + dual css/js imports
MIT License
114 stars 41 forks source link

Do usual imports() also work with that plugin? #38

Closed egorvoronov closed 6 years ago

egorvoronov commented 6 years ago

Hi James,

thanks for this work, it's amazing!!

I'd like to clarify one moment here. What if I have not universal components but only some js that I would like also to lazy load. I'm doing this with usual:

export default const getSomeLibrary = () => import('./some-library');

and then like

import getSomeLibrary from '../getSomeLibrary';

getSomeLibrary().then(somelibrary => somelibrary(doSomething));
(0, _universalImport3.default)({
                id: './some-library',
                file: '/project/app.js',
                load: function load() {
                    return Promise.all([Promise(...), (0, _importCss3.default)('somelibrary', {})]).then(function (proms) {
                        return proms[0];
                    });
                },
                path: function path() {
                    return _path3.default.join(...);
                },
                resolve: function resolve() {
                    ...
                },
                chunkName: function chunkName() {
                    return 'some-library';
                }
            });

and it looks like it tries to apply universal code here but it shouldn't, right?

ScriptedAlchemy commented 6 years ago

Its babel transform, so its changing the syntax.

The beauty here is if use the lates of this repo. theres the default then and catch that youd find in a promise. If you arent up to date, that might cause you some issues. But ive extensively worked with this plugin and system. import() is import() all functions the same way

faceyspacey commented 6 years ago

Yea, (0, _universalImport3.default) internally insures you can use the promise returned from import() as usual:

https://github.com/faceyspacey/babel-plugin-universal-import/blob/master/universalImport.js#L3-L18

I think there was a bug related to it I fixed 2 months ago. Let me know if you're still having problems using the promise regularly. Gonna close this out for now, but feel free to keep the thread going.

rtymchyk commented 4 years ago

If anyone is looking at this issue, you must use Promises for babel-plugin-universal-import not to interfere with dynamic imports like this, async/await will not do.