简体   繁体   中英

Combine js files from different directories via config using grunt

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.

You can use grunt concat

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM