是否可以通过在中心点上拥有所需模块的方式来配置 grunt?
我有以下项目结构
-Project
-- subproject
-- subproject
-- subproject
我通过 grunt 构建所有子项目的项目,我也可以为自己构建每个子项目。目前我有一个 Gruntfile.js、package.json 和文件夹 node_modules (~50mb),其中包含每个子项目和根级别的所有必需模块。
那么是否可以将 node_modules 文件夹仅放在一个级别上,例如在根级别上,而子项目在根级别上引用 node_modules?
-Project
--subproject
--subproject
--subproject
--node_modules
有没有办法通过 package.json 或其他方式引用 node_module 文件夹?
编辑:
Gruntfile.js(子项目级别)
/*global module:false */
/*jshint node:true */
module.exports = function(grunt) {
"use strict";
// ================================================================================
// project configuration
// ================================================================================
grunt.initConfig({
pkg : grunt.file.readJSON('package.json'),
jshint: {
globals : {
d3:true,
Modernizr:true,
tempo:true
},
options: grunt.file.readJSON('.jshintrc')
},
csslint: {
subproject: {
src: 'css/**/*.css'
}
},
htmllint : {
subproject: {
src: 'html/**/*.html'
}
},
clean : [ 'output' ],
less : {
options: {
paths: ['./']
},
src: {
expand: true,
cwd: 'css/',
src: ['**/*.less'],
dest: 'css/',
ext: '.css'
}
},
copy: {
subproject: {
files: [
{src: ['img/**', 'js/**', 'folderX/**','!**/*.less'], dest: 'output/subproject/'}
]
}
}
});
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-html');
grunt.loadNpmTasks('grunt-css');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-copy');
// ================================================================================
// default task
// ================================================================================
grunt.registerTask('default', ['clean', 'less', 'csslint', 'htmllint', 'copy']);
};
package.json(子项目级别)
{
"description": "subproject",
"title": "Lorem Ipsum",
"devDependencies": {
"grunt-contrib-watch": "~0.2.0",
"grunt-contrib-jshint": "~0.1.1",
"grunt-contrib-less": "~0.5.0",
"grunt-contrib-uglify": "~0.1.1",
"grunt-contrib-copy": "~0.4.0",
"grunt-contrib-qunit": "~0.1.1",
"grunt-css": "~0.5.4",
"grunt-contrib-clean": "~0.4.0",
"grunt-html": "~0.3.3",
"grunt-contrib-concat": "~0.1.3"
}
}
BR,迈贝克