Combine js files from different directories via config using grunt

61 views Asked by At

I'm using grunt and sass and I'm looking for a sass-like feature to import any JS file I like to and combine them to 1 file via some config depending on the directory I am in.

Example directories:

startpage
  file1.js
  file2.js
  importjs.json
page1
  file3.js
  file4.js
  importjs.json
global
  global1.js
  global2.js

Each directory besides global is one being used by a single page. Global includes js files used on multiple pages.

Right now grunt is only combining the js files within a directory. Means file1.js and file2.js is getting combined to startpage.js.

What I want is to have a json/txt/whatever file for each directory to specify the files which I want in my startpage.js.

Like file1.js, global2.js and page1/file4.js

Is there a way to accomplish this using grunt? It can also be 1 single config file with an array where I can specify the js files I need for each site. Those files need to be combined and minified.

1

There are 1 answers

2
Atrotors On BEST ANSWER

You can use grunt concat

concat: {
  dist: {
    src: [
      'startpage/file1.js',
      'startpage/file2.js'
    ],
    dest: 'startpage.js'
  }
},