6

I have require which executes itself and saves result into variable

var $ = require('gulp-load-plugins')();

I am playing with Babel and trying to figure out how to do this in ES6. Now obviously I could do something like

import gulpLoadPlugins from 'gulp-load-plugins';
const $ = gulpLoadPlugins();

But I was wondering if there is some nice one liner way to do it, like with require.

Leonid Beschastny
  • 50,364
  • 10
  • 118
  • 122
Petr Hurtak
  • 2,239
  • 1
  • 19
  • 18
  • It's not possible. Import does not return a value. For cases such as this, it's not bad to use require, although I guess the second version is probably going to cause fewer heads to be scratched. – Matthew King Jul 05 '15 at 09:24
  • Best you can do if you don't have dynamic imports: `import lp from 'gulp-load-plugins'; const $ = lp();` If you have dynamic imports: `const $ = (await import('gulp-load-plugins'))();` – ADJenks May 23 '19 at 00:03

1 Answers1

13

But I was wondering if there is some nice one liner way to do it, like with require.

No there is not.

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
  • If he has dynamic imports and is inside an async function: `const $ = (await import('gulp-load-plugins'))();` – ADJenks May 23 '19 at 00:05