Skip to content

Instantly share code, notes, and snippets.

@qstudio
Last active September 17, 2020 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qstudio/6fe39c2917d177a0b834d931001782ef to your computer and use it in GitHub Desktop.
Save qstudio/6fe39c2917d177a0b834d931001782ef to your computer and use it in GitHub Desktop.
'use strict';
module.exports = function(grunt) {
// root path to mode_modules - crude, but stable ##
var $root_path = '../../../';
// Load Tasks ##
grunt.loadTasks( $root_path+'node_modules/grunt-contrib-clean/tasks' ); // Clean ##
grunt.loadTasks( $root_path+'node_modules/grunt-contrib-watch/tasks'); // Watcher ##
grunt.loadTasks( $root_path+'node_modules/grunt-postcss/tasks'); // Post Processing ##
grunt.loadTasks( $root_path+'node_modules/grunt-dart-sass/tasks'); // DART SASS ##
grunt.loadTasks( $root_path+'node_modules/grunt-contrib-uglify/tasks'); // UGLIFY / Minify JS ##
// ------- configuration ------- ##
grunt.initConfig({
'config': {
// module data stored from Q ##
'q_modules': grunt.file.readJSON('q.module.json'),
// logging options ##
'verbosity': {
'default': {
'options': { mode: 'online' }, // normal, oneline, dot, hidden
'tasks': [ 'deploy' ]
}
},
'sass': {
// common SCSS root for easier SCSS @use / @forward usage ##
'includePaths': [
'../' // wp-content/themes/ - cherry pick from all themes ##
],
// sass controller file ##
'src': [
'library/_source/scss/index.scss',
],
// main destination file ##
'dest': 'library/asset/css/theme.css',
},
'postcss': {
// main destination file ##
'dest': 'library/asset/css/theme.css',
// minified destination file ##
'min': 'library/asset/css/theme.min.css',
},
// object of files to clean up pre-compile ##
'clean': {
'css': [
'library/asset/css/*.css', // regex to find all generated css files ##
'library/asset/css/*.map', // regex to find all generated map files ##
],
'js': [
'library/asset/**/*.min.js', // all .min.js ##
'library/asset/**/*.js.map', // all .js.map ##
]
},
// files to watch ##
'watch': {
'sass' : [
'library/_source/scss/view/*.scss', // regex to track all Template files ##
'library/_source/scss/ui/*.scss', // regex to track all UI files ##
'library/_source/scss/q/*.scss', // regex to track all Q/config files ##
'library/_source/scss/module/*.scss', // regex to track all module files ##
'library/_source/scss/plugin/*.scss', // regex to track all plugin files ##
// 'library/_source/scss/bootstrap/*.scss', // regex to track main Bootstrap include ##
]
},
'uglify': {
'theme': {
'dest': 'library/asset/js/theme.min.js',
'src' : [ 'library/_source/js/theme.js' ]
},
'module': {
'dest': 'library/asset/js/module.min.js',
'src' : '<%= config.q_modules.javascript_path %>'// loaded from /q.module.json, can include parent and child references ##
}
},
},
// ------- end config ------- ##
'uglify': {
'theme': {
'options': {
'beautify': false,
'mangle': true, // allow mangling
'banner': '/*! Q Studio Theme ~~ <%= grunt.template.today("dddd, mmmm dS, yyyy, h:MM:ss TT") %> */\n',
'sourceMap': function(path) { return path.replace(/.js$/,".js.map")},
'sourceMapIncludeSources': true,
'compress': {
conditionals: true,
booleans: true,
unused: true,
sequences: true,
dead_code: true,
if_return: true,
join_vars: true,
drop_console: true
}
},
files:{
'<%= config.uglify.theme.dest %>' : '<%= config.uglify.theme.src %>'
}
},
'module': {
'options': {
'beautify': false,
'mangle': true, // allow mangling
'banner': '/*! Q Studio Modules ~~ <%= grunt.template.today("dddd, mmmm dS, yyyy, h:MM:ss TT") %> */\n',
'sourceMap': function(path) { return path.replace(/.js$/,".js.map")},
'sourceMapIncludeSources': true,
'compress': {
conditionals: true,
booleans: true,
unused: true,
sequences: true,
dead_code: true,
if_return: true,
join_vars: true,
drop_console: true
}
},
files:{
'<%= config.uglify.module.dest %>' : '<%= config.uglify.module.src %>'
}
}
},
// clean up old compilled files ##
'clean': {
'css': '<%= config.clean.css %>',
'js': '<%= config.clean.js %>'
},
// SASS compiller ##
'dart-sass': {
'target': {
'options': {
'outputStyle' : 'expanded',
'sourceMap' : true,
'includePaths' : '<%= config.sass.includePaths %>',
'lineNumber' : true,
},
'files': {
'<%= config.sass.dest %>': '<%= config.sass.src %>'
}
}
},
// watch task ##
'watch': {
// track changes to scss _source files ##
'sass': {
'options': {
},
'files':
'<%= config.watch.sass %>'
,
'tasks': [
'default' // css tasks... ##
]
}
/*
// track changes to js _source files ##
'js': {
'options': {
},
'files':
'<%= config.watch.js %>'
,
'tasks': [
'default' // JS tasks ##
]
},
*/
},
// post processing formating ##
'postcss': {
'options': {
'map': true, // inline sourcemaps
'processors': [
// add fallbacks for rem units ##
require('pixrem')(),
// add vendor prefixes -- options defined in package.json 'browserslist' ##
require('autoprefixer')(),
]
},
'dist': {
'src': '<%= config.postcss.dest %>',
'dest': '<%= config.postcss.dest %>',
},
'minify': {
'options': {
'processors': [
require('cssnano')() // minifies ##
]
},
'src': '<%= config.postcss.dest %>',
'dest': '<%= config.postcss.min %>',
}
},
});
// Development Tasks ##
grunt.registerTask( 'default', [
'dart-sass', // Dart SASS ##
// 'clean:js', // clean up old compiled files ##
// 'uglify:theme', // minify js /_source/js to /assets/js
// 'uglify:module', // minify js /_source/js to /assets/js
// 'postcss', // post processing formating ## ##
]);
// Prepare for deployment Tasks ##
grunt.registerTask( 'deploy', [
'clean', // clean up old compiled files ##
'dart-sass', // Dart SASS ##
'postcss', // post processing formating ## ##
'uglify:theme', // minify js /_source/js to /assets/js
'uglify:module', // minify js /_source/js to /assets/js
]);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment