1

I have 21 lines of import statements. Is there any solution to reduce this number of lines?

import through from 'through2';
import gulp from 'gulp';
import watch from 'gulp-watch';
import rename from 'gulp-rename';
import data from 'gulp-data';
import jade from 'gulp-jade';
import debug from 'gulp-debug';
import replace from 'gulp-replace';
// and so on

PS. 21 import lines in whole 82sloc gulpfile is pretty annoying thing

Vladimir Starkov
  • 19,264
  • 8
  • 60
  • 114
  • Once you run it through a minifier it will all be a single line. What's the problem with number of lines? – Xotic750 Jun 16 '15 at 20:14
  • 1
    And that makes the number of lines a problem because? – Xotic750 Jun 16 '15 at 20:28
  • I would think that you could re-export everything that you need in a separate file, see: http://www.2ality.com/2014/09/es6-modules-final.html (re-exporting) and then import just that single file. But I never tried it thus I will just leave a comment and ask you to try it out. – Oleg Berman Jun 16 '15 at 20:30
  • Why is there a problem with the number of lines? – bhspencer Jun 16 '15 at 20:30
  • @bhspencer i have 82sloc gulpfile and 21 of them are imports, it’s annoying – Vladimir Starkov Jun 16 '15 at 20:31
  • Although in my personal opinion you have to keep imports in the same file for it to be self-explanatory (how many modules are used and why) and don't worry about the line count. There are way more other more important things out there that make your code better & more readable. – Oleg Berman Jun 16 '15 at 20:35
  • @Xotic750 yes, if quarter of my gulpfile is imports, then it’s annoying – Vladimir Starkov Jun 16 '15 at 20:35
  • I don't find your annoyance a problem. You could probably create an array of objects like `[{through:"through2}]` and loop through them and import into an object `var imp = {}; forEach ... import imp[key] from item[key]`, doubt it will make the code smaller or more readable. – Xotic750 Jun 16 '15 at 20:43
  • @Xotic750 you are not me, probably, that’s why 21imports is a problem for me and for you. – Vladimir Starkov Jun 16 '15 at 20:46
  • @Xotic750 thanks for proposed solution, but probably I will keep it as is – Vladimir Starkov Jun 16 '15 at 20:48
  • Your welcome. Keeping it as it is seems most sensible to me, but then number of lines has never worried me, readability and maintainability have a much higher priority in my book. :) – Xotic750 Jun 16 '15 at 20:50

0 Answers0