Skip to content

Instantly share code, notes, and snippets.

@aamnah

aamnah/grunt-snippets.sh

Last active Oct 21, 2017
Embed
What would you like to do?
Bash script for creating Grunt snippets for Sublime Text (gruntfile, cssmin, imagemin, uglify, s3, watch)
#!/bin/bash
# Author: Aamnah Akram
# URL: http://aamnah.com
# Email: hello@aamnah.com
# Description: Bash script for creating Grunt snippets for Sublime Text (gruntfile, cssmin, imagemin, uglify, s3, watch)
# Install: Open a Terminal and `cd` to the folder you downloaded the script in.
# Run the script by typing `bash grunt-snippets.sh`. It will add all the below snippets to the packages folder.
cd ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/User
touch grunt.sublime-snippet && echo "
<snippet>
<description>Gruntfile.js Skeleton</description>
<tabTrigger>grunt</tabTrigger>
<content><![CDATA[
module.exports = function(grunt) {
// Configure task(s)
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
});
// Load the plugin(s)
grunt.loadNpmTasks( );
// Register task(s)
grunt.registerTask('default', [ ]);
};
]]></content>
</snippet>" >> grunt.sublime-snippet
touch uglify.sublime-snippet && echo "
<snippet>
<description>Minify files with UglifyJS</description>
<tabTrigger>uglify</tabTrigger>
<content><![CDATA[
uglify: {
// Basic compression
my_target: {
files: {
'dest/output.min.js': ['src/input1.js', 'src/input2.js']
}
}
},
]]></content>
</snippet>
" >> uglify.sublime-snippet
touch s3.sublime-snippet && echo "
<snippet>
<description>https://github.com/jpillora/grunt-aws</description>
<tabTrigger>s3</tabTrigger>
<content><![CDATA[
aws: grunt.file.readJSON('credentials.json'),
s3: {
// upload all files inside build/ into my-awesome-bucket:
options: {
accessKeyId: '<%= aws.accessKeyId %>',
secretAccessKey: '<%= aws.secretAccessKey %>',
bucket: 'my-awesome-bucket'
},
build: {
cwd: 'build/',
src: '**''
}
},
]]></content>
</snippet>
" >> s3.sublime-snippet
touch imagemin.sublime-snippet && echo "
<snippet>
<description>Minify Images</description>
<tabTrigger>imagemin</tabTrigger>
<content><![CDATA[
imagemin: { // Task
static: { // Target
options: { // Target options
optimizationLevel: 3,
svgoPlugins: [{ removeViewBox: false }],
use: [mozjpeg()]
},
files: { // Dictionary of files
'dist/img.png': 'src/img.png', // 'destination': 'source'
'dist/img.jpg': 'src/img.jpg',
'dist/img.gif': 'src/img.gif'
}
},
dynamic: { // Another target
files: [{
expand: true, // Enable dynamic expansion
cwd: 'src/', // Src matches are relative to this path
src: ['**/*.{png,jpg,gif}'], // Actual patterns to match
dest: 'dist/' // Destination path prefix
}]
}
},
]]></content>
</snippet>
" >> imagemin.sublime-snippet
touch cssmin.sublime-snippet && echo "
<snippet>
<description>Minify CSS</description>
<tabTrigger>cssmin</tabTrigger>
<content><![CDATA[
cssmin: {
// Combine two files into one output file
options: {
shorthandCompacting: false,
roundingPrecision: -1
},
target: {
files: {
'output.css': ['foo.css', 'bar.css']
}
}
},
cssmin: {
// Minify all contents of a release directory and add a .min.css extension
target: {
files: [{
expand: true,
cwd: 'release/css',
src: ['*.css', '!*.min.css'],
dest: 'release/css',
ext: '.min.css'
}]
}
},
]]></content>
</snippet>
" >> cssmin.sublime-snippet
touch watch.sublime-snippet && echo "
<snippet>
<description>Run predefined tasks whenever watched file patterns are added, changed or deleted</description>
<tabTrigger>watch</tabTrigger>
<content><![CDATA[
watch: {
scripts: {
files: ['**/*.js'],
tasks: ['jshint'],
options: {
spawn: false,
},
},
},
]]></content>
</snippet>
" >> watch.sublime-snippet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.