随着NPM作为Build-Tool越来越受欢迎,它可以取代Grunt和Gulp。 (因为它可以从一开始就做)我想和它一起去。
但是我能在这个主题上找到的罕见信息对我来说仍然有点混乱。
当我通过示例更好地学习时,我的问题是:
任何人都可以为我提供此Gruntfile.js的替换吗?
我认为它可以在未来为人们提供很多帮助。
如果需要更改,还需要package.json。
加上终端命令,因为我认为它需要更多或其他东西,只需grunt watch
Gruntfile.js
module.exports = function(grunt){
require("matchdep").filterDev("grunt-*").forEach(grunt.loadNpmTasks);
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
sass: {
dist: {
options: {
style: 'compressed'
},
files: {
'build/css/style.css' : 'src/scss/combined.scss'
}
}
},
imagemin: {
dynamic: {
options: {
optimizationLevel: 3
},
files: [{
expand: true,// Enable dynamic expansion
cwd: 'assets/img/',
src: ['**/*.{png,jpg,gif}'],
dest: 'build/img/'
}]
}
},
concat: {
vendorJs: {
src: ['src/js/vendor/*.js'],
dest: 'src/js/vendor.js'
}
},
uglify: {
js: {
files: {
'build/js/main.min.js': ['src/js/main.js']
}
},
vendorJs: {
files: {
'build/js/vendor.min.js': ['src/js/vendor.js']
}
}
},
cssmin: {
minify: {
expand: true,
cwd: 'src/scss/',
src: ['*.css', '!*.min.css'],
dest: 'build/css/',
ext: '.min.css'
}
},
jshint: {
beforeconcat: ['src/js/main.js'],
afterconcat: ['build/js/main.min.js']
},
watch: {
css: {
files: '**/*.scss',
tasks: ['sass','cssmin']
},
js : {
files : 'src/js/**/*.js',
tasks : ['concat','uglify']
},
images: {
files: ['assets/img/**/*.{png,jpg,gif}'],
tasks: ['imagemin'],
options: {
spawn: false
}
}
}
});
grunt.registerTask('default', []);
};
的package.json
{
"name": "project_name",
"version": "1.0.0",
"author": "your name",
"private": true,
"devDependencies": {
"grunt": "^0.4.5",
"grunt-contrib-concat": "^0.5.0",
"grunt-contrib-cssmin": "^0.10.0",
"grunt-contrib-jshint": "^0.10.0",
"grunt-contrib-sass": "^0.7.4",
"grunt-contrib-uglify": "^0.5.1",
"grunt-contrib-watch": "^0.6.1",
"matchdep": "*"
}
}