假设我们有一个名为 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 中为每个项目安装模块吗?
如果您需要更多信息或者我的英语不好,请询问我任何问题,我会更新我的问题。
谢谢
最佳答案
您可以使用load-grunt-parent-tasks来做到这一点。
我知道我没有使用这个插件,但我想我会帮助你。
关于javascript - 是否可以为存储库中的多个项目使用一个 node_module 文件夹?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30617174/