admin管理员组文章数量:1192157
Is it possible to put Grunt config files in a sub directory of the project? I want to do this to keep things more organised.
E.g.
myproject/grunt/Gruntfile.js
myproject/grunt/package.json
myproject/grunt/node_modules/
I'm having problems running commands from Gruntfile.js under this configuration. Can Grunt handle looking to the parent directory? Or maybe I'm doing it wrong
sass: {
dev: {
files: {
"../style.css": "../scss/style.scss"
}
}
}
When I run this Grunt just seems to shrug, not understanding that I want it to look in the parent directory…
Source file "scss/style.scss" not found.
Is it possible to put Grunt config files in a sub directory of the project? I want to do this to keep things more organised.
E.g.
myproject/grunt/Gruntfile.js
myproject/grunt/package.json
myproject/grunt/node_modules/
I'm having problems running commands from Gruntfile.js under this configuration. Can Grunt handle looking to the parent directory? Or maybe I'm doing it wrong
sass: {
dev: {
files: {
"../style.css": "../scss/style.scss"
}
}
}
When I run this Grunt just seems to shrug, not understanding that I want it to look in the parent directory…
Source file "scss/style.scss" not found.
Share
Improve this question
edited Aug 12, 2013 at 20:50
Steve P
19.4k7 gold badges72 silver badges96 bronze badges
asked Aug 12, 2013 at 19:25
SparrwHawkSparrwHawk
14.2k22 gold badges62 silver badges92 bronze badges
1 Answer
Reset to default 28Yes, this should be possible, but you will probably want to use the grunt.file.setBase method or the --base
command-line option to make the tasks work just like you had put the Gruntfile in the root of the project. Otherwise, you will run into various issues with tasks that, by default, will not write to paths outside the working directory. For example, the force option on the grunt-contrib-clean plugin.
Here is an example which modifies the sample Gruntfile from the Getting Started page to use this method:
module.exports = function(grunt) {
// if you put the call to setBase here, then the package.json and
// loadNpmTasks paths will be wrong!!!
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
uglify: {
options: {
banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
},
build: {
src: 'src/<%= pkg.name %>.js',
dest: 'build/<%= pkg.name %>.min.js'
}
}
});
// Load the plugin that provides the "uglify" task.
grunt.loadNpmTasks('grunt-contrib-uglify');
// now that we've loaded the package.json and the node_modules we set the base path
// for the actual execution of the tasks
grunt.file.setBase('../')
// Default task(s).
grunt.registerTask('default', ['uglify']);
};
I don't use SASS, so can't comment on whether anything might be wrong with your task config, but the above works as a modification of the Getting Started example.
本文标签: javascriptPut Grunt in a subdirectoryStack Overflow
版权声明:本文标题:javascript - Put Grunt in a subdirectory - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738463180a2088148.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论