Last active
March 18, 2021 19:53
-
-
Save gecugamo/e4d2f931d943d0e0a9af to your computer and use it in GitHub Desktop.
Gruntfile.js with sass, postcss, concat, uglify, and watch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function(grunt) { | |
grunt.initConfig({ | |
pkg: grunt.file.readJSON('package.json'), | |
sass: { | |
dist: { | |
options: { | |
sourcemap: 'inline' | |
}, | |
files: { | |
'dist/css/style.css' : 'src/scss/style.scss' | |
} | |
} | |
}, | |
postcss: { | |
options: { | |
map: true, // inline sourcemaps | |
processors: [ | |
require('pixrem')(), // add fallbacks for rem units | |
require('autoprefixer')({browsers: 'last 2 versions'}), // add vendor prefixes | |
require('cssnano')() // minify the result | |
] | |
}, | |
dist: { | |
'dist/css/style.css' | |
} | |
}, | |
concat: { | |
options: { | |
separator: ';\n' | |
}, | |
dist: { | |
src: [ | |
'src/js/script.js' | |
], | |
dest: 'dist/js/script.concat.js' | |
} | |
}, | |
uglify: { // Begin JS Minify Plugin | |
build: { | |
src: 'dist/js/script.concat.js', | |
dest: 'dist/js/script.min.js' | |
} | |
}, | |
watch: { | |
grunt: { | |
options: { | |
reload: true | |
}, | |
files: ['Gruntfile.js'] | |
}, | |
css: { | |
files: ['src/scss/*.scss', 'src/scss/**/*.scss'], | |
tasks: ['sass', 'postcss'] | |
}, | |
js: { | |
files: ['src/js/*.js', 'src/js/**/*.js'] | |
tasks: ['concat, uglify'] | |
} | |
} | |
}); | |
grunt.loadNpmTasks('grunt-contrib-sass'); | |
grunt.loadNpmTasks('grunt-postcss'); | |
grunt.loadNpmTasks('grunt-contrib-concat'); | |
grunt.loadNpmTasks('grunt-contrib-uglify'); | |
grunt.loadNpmTasks('grunt-contrib-watch'); | |
grunt.registerTask('default', ['watch']); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment