是否可以为存储库中的多个项目创建一个node_module文件夹?

时间:2015-06-03 10:13:57

标签: javascript git gruntjs npm

假设我们有一个存储库名称REPO,其中包含几个grunt项目。让我们想要结构:

ROOT
-- bower_components
-- node_modules
-- project_1
-- project_2
-- project_3 etc

现在的问题是我需要为每个项目提供不同的gruntfile.js,所以我可以拥有不同的分布式缩小的js文件,不同的任务等。

我现在所拥有的解决方案,但完全没有帮助,每个项目文件夹都有自己的node_module文件夹,包含所有需要的模块。

所以我得到了这个,我想像上面的架构一样改变它。

ROOT
-- bower_components
-- project_1
---- node_modules
-- project_2
---- node_modules
-- project_3
---- node_modules

现在每个gruntfile都是这样的:

function config(name) {
  return require ('./tasks/' + name + '.js');
}

module.exports = function (grunt){

  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    jshint: config('jshint'),
    concat: config('concat'),
    uglify: config('uglify'),
    cssmin: config('cssmin'),
    jsbeautifier: config('jsbeautifier'),
    watch: {
      options: {livereload: true},
      files: ['index.html', 'app/views/**/*.html', 'app/css/*.css', 'js/*.js'],
      tasks: ['jshint']
    },
    karma: {
      unit: {
        configFile: 'test/test.conf.js'
      }
    }

  });

  //load plugins
  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-contrib-concat');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-contrib-cssmin');
  grunt.loadNpmTasks('grunt-jsbeautifier');
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-karma');

  //tasks
  grunt.registerTask('dist', ['jshint', 'concat', 'uglify', 'cssmin', 'jsbeautifier']);
  grunt.registerTask('default', ['watch']);

};

我可以为每个NpmTask添加一个路径,而不是在我的REPO中为每个项目安装模块吗?

如果您需要更多信息或我的英语不好问我什么,我会更新我的问题。

由于

1 个答案:

答案 0 :(得分:1)

您可以使用load-grunt-parent-tasks来执行此操作。

我知道我没有使用这个插件,但我想我会帮助你。

相关问题