-1

Is there a way to write a main file like so:

// main.js
var foo = 'foo';
        require('./bar.js'); // or import ...etc
var baz = 'baz';
// bar.js
var bar = 'bar';

then i should get this concatinated file like so:

// main.js
var foo = 'foo';
        // bar.js
        var bar = 'bar';
var baz = 'baz';

i don't want some side effects like wrapping the main file or exporting it, i just want a simple concatination, and indentations also should be respected.

it's just like gulp-concat but with require or import, like PHP include

I need a solution to work with Gulp or nodejs directly.

elkebirmed
  • 2,247
  • 6
  • 24
  • 35

1 Answers1

1

Either use something like require.js clientside, or do some sort of preprocessing serverside. Anyway you'll have to get used to requirements and limitation of the way you choose. You even can use some sort of templating engine, like Smarty mayde, it can include code just like php does it, but don't forget about caching.

Also if you want to create web application modern way - take a look at angular.js, ember.js, etc. There are lots of them there by now, take what's better for your needs.

BI2O2T
  • 91
  • 5