Skip to content

Instantly share code, notes, and snippets.

@honsa
Created March 1, 2018 18:20
Show Gist options
  • Save honsa/f5d97b77e271f1389a2eca6f5798a8ee to your computer and use it in GitHub Desktop.
Save honsa/f5d97b77e271f1389a2eca6f5798a8ee to your computer and use it in GitHub Desktop.
working sourcemap grunt sass
module.exports = function(grunt) { // The general grunt function that is run
//local folders
const srcSassFolder = 'sass';
const srcJsFolder = 'js';
const publicCssFolder = 'public/css';
const publicJsFolder = 'public/js';
grunt.initConfig({ // Here we setup our config object with package.json and all the tasks
pkg: grunt.file.readJSON('package.json'),
sass: { // Begin sass tasks
dist: {
options: {
sourceMap: true,
style: 'expanded'
},
files: [{
expand: true,
cwd: 'sass',
src: ['*.scss'],
dest: publicCssFolder,
ext: '.css'
}]
}
},
postcss: { // Begin Post CSS Plugin
options: {
map: true,
processors: [
require('autoprefixer')({
browsers: ['last 3 versions']
})
]
},
dist: {
src: publicCssFolder + '/*.css'
}
},
cssmin: { // Begin CSS Minify Plugin
options: {
sourceMap: true
},
target: {
files: [{
expand: true,
cwd: publicCssFolder,
src: ['*.css', '!*.min.css'],
dest: publicCssFolder,
ext: '.min.css'
}]
}
},
uglify: { // Begin JS Uglify Plugin
build: {
files: [{
expand: true,
cwd: srcJsFolder,
src: '*.js',
dest: publicJsFolder,
ext: '.min.js'
}]
}
},
watch: { // Watch task for general work
options: { banner: 'dsad'},
css: {
files: srcSassFolder + '/**/*.scss',
tasks: ['sass', 'postcss', 'cssmin']
},
js: {
files: srcJsFolder + '/**/*.js',
tasks: ['uglify']
}
}
});
// All the plugins that is needed for above tasks
grunt.loadNpmTasks('grunt-sass');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-postcss');
grunt.loadNpmTasks('grunt-contrib-uglify');
// Registering the default task that we're going to use along with watch
grunt.registerTask('styles', ['sass', 'postcss', 'cssmin']);
grunt.registerTask('javascript', ['uglify']);
grunt.registerTask('default', ['watch']);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment