grunt将所有内容都添加到新文件中

时间:2016-12-05 19:38:39

标签: javascript gruntjs mean-stack

我有以下源视图

enter image description here

是否可以通过grunt将所有这些文件放入例如名为content.js的文件中并加载它?所以当发出对服务器的请求时,content.js将包含所有代码吗?

我想要一种自动执行此操作的方法。

修改

尝试https://github.com/gruntjs/grunt-contrib-concat 但有了这些细节:

  dist: {
        src: ['modules/*/client/*/*.js'],
        dest: 'public/js/built.js',
      },

似乎没有用。

1 个答案:

答案 0 :(得分:0)

是的,这是可能的。使用grunt-contrib-concat

// minimum example:
grunt.initConfig({
  concat: {
    options: {
      separator: ';',
    },
    dist: {
      src: ['src/path/to/your/scripts/**/*.js'], // if you need some specific order
                                                 // list files or directories individually
                                                 // and read below's recommendation                            
      dest: 'dist/built.js',
    },
  },
});

然而,考虑到你的项目看起来有点广泛的事实,我宁愿建议更大的步骤,以及更多的智能"依赖关系管理,例如BrowserifyWebpack