woocommerce/Gruntfile.js

232 lines
4.2 KiB
JavaScript
Raw Normal View History

2014-08-01 12:53:31 +00:00
module.exports = function( grunt ) {
2014-02-02 19:20:52 +00:00
'use strict';
var sass = require( 'node-sass' );
2014-01-30 16:11:02 +00:00
2014-02-02 19:22:05 +00:00
grunt.initConfig({
2014-10-23 21:42:07 +00:00
// Setting folder templates.
dirs: {
css: 'assets/css',
fonts: 'assets/fonts',
images: 'assets/images',
2019-02-23 01:00:47 +00:00
js: 'assets/js',
php: 'includes'
},
// JavaScript linting with ESLint.
eslint: {
src: [
2014-08-04 14:12:50 +00:00
'<%= dirs.js %>/admin/*.js',
'!<%= dirs.js %>/admin/*.min.js',
'<%= dirs.js %>/frontend/*.js',
2019-02-04 11:24:26 +00:00
'!<%= dirs.js %>/frontend/*.min.js'
2014-08-04 14:12:50 +00:00
]
},
2016-08-08 19:32:39 +00:00
// Sass linting with Stylelint.
stylelint: {
options: {
2016-11-07 17:47:05 +00:00
configFile: '.stylelintrc'
2016-08-08 19:32:39 +00:00
},
all: [
2016-08-10 13:15:58 +00:00
'<%= dirs.css %>/*.scss',
'!<%= dirs.css %>/select2.scss'
2016-08-08 19:32:39 +00:00
]
},
// Minify .js files.
uglify: {
options: {
2017-06-19 11:49:27 +00:00
ie8: true,
parse: {
strict: false
},
output: {
comments : /@license|@preserve|^!/
}
},
js_assets: {
files: [{
expand: true,
cwd: '<%= dirs.js %>/',
src: [
'**/*.js',
'!**/*.min.js'
],
extDot: 'last',
dest: '<%= dirs.js %>',
ext: '.min.js'
}]
2014-09-22 16:55:53 +00:00
}
},
// Compile all .scss files.
sass: {
compile: {
options: {
implementation: sass,
2017-06-26 17:16:46 +00:00
sourceMap: 'none'
},
2014-09-22 16:55:53 +00:00
files: [{
expand: true,
cwd: '<%= dirs.css %>/',
src: ['*.scss'],
dest: '<%= dirs.css %>/',
ext: '.css'
}]
}
},
// Generate RTL .css files.
rtlcss: {
woocommerce: {
expand: true,
cwd: '<%= dirs.css %>',
src: [
'*.css',
2017-02-10 19:39:28 +00:00
'!select2.css',
'!*-rtl.css'
],
dest: '<%= dirs.css %>/',
ext: '-rtl.css'
}
},
2014-08-04 14:12:50 +00:00
// Minify all .css files.
cssmin: {
minify: {
files: [
{
expand: true,
cwd: '<%= dirs.css %>/',
src: ['*.css'],
dest: '<%= dirs.css %>/',
ext: '.css'
},
{
expand: true,
cwd: '<%= dirs.css %>/photoswipe/',
src: ['*.css', '!*.min.css'],
dest: '<%= dirs.css %>/photoswipe/',
ext: '.min.css'
},
{
expand: true,
cwd: '<%= dirs.css %>/photoswipe/default-skin/',
src: ['*.css', '!*.min.css'],
dest: '<%= dirs.css %>/photoswipe/default-skin/',
ext: '.min.css'
}
]
2014-08-04 14:12:50 +00:00
}
},
// Concatenate select2.css onto the admin.css files.
concat: {
admin: {
files: {
'<%= dirs.css %>/admin.css' : ['<%= dirs.css %>/select2.css', '<%= dirs.css %>/admin.css'],
'<%= dirs.css %>/admin-rtl.css' : ['<%= dirs.css %>/select2.css', '<%= dirs.css %>/admin-rtl.css']
}
2017-02-16 10:44:43 +00:00
}
},
// Watch changes for assets.
2014-02-02 21:33:20 +00:00
watch: {
2014-09-22 16:55:53 +00:00
css: {
files: ['<%= dirs.css %>/*.scss'],
tasks: ['sass', 'rtlcss', 'postcss', 'cssmin', 'concat']
2014-02-02 21:33:20 +00:00
},
js: {
files: [
'GruntFile.js',
'<%= dirs.js %>/**/*.js',
'!<%= dirs.js %>/**/*.min.js'
2014-02-02 21:33:20 +00:00
],
tasks: ['eslint','newer:uglify']
2014-02-02 21:33:20 +00:00
}
},
2016-09-13 21:24:01 +00:00
// PHP Code Sniffer.
phpcs: {
options: {
2017-10-10 16:08:23 +00:00
bin: 'vendor/bin/phpcs'
2016-09-13 21:24:01 +00:00
},
dist: {
src: [
2019-01-10 12:01:27 +00:00
'**/*.php', // Include all php files.
'!includes/api/legacy/**',
'!includes/libraries/**',
'!node_modules/**',
'!tests/cli/**',
'!tmp/**',
'!vendor/**'
2016-09-13 21:24:01 +00:00
]
}
2017-04-29 15:23:01 +00:00
},
2017-05-04 22:29:40 +00:00
// Autoprefixer.
postcss: {
2017-04-29 15:23:01 +00:00
options: {
processors: [
require( 'autoprefixer' )
2017-04-29 15:23:01 +00:00
]
},
dist: {
src: [
'<%= dirs.css %>/*.css'
]
}
2014-02-10 14:29:41 +00:00
}
2014-02-02 19:22:05 +00:00
});
2014-01-30 16:11:02 +00:00
// Load NPM tasks to be used here.
2017-06-26 17:16:46 +00:00
grunt.loadNpmTasks( 'grunt-sass' );
grunt.loadNpmTasks( 'grunt-phpcs' );
grunt.loadNpmTasks( 'grunt-rtlcss' );
2017-06-26 17:16:46 +00:00
grunt.loadNpmTasks( 'grunt-postcss' );
grunt.loadNpmTasks( 'grunt-stylelint' );
grunt.loadNpmTasks( 'gruntify-eslint' );
grunt.loadNpmTasks( 'grunt-contrib-uglify' );
2014-09-22 16:55:53 +00:00
grunt.loadNpmTasks( 'grunt-contrib-cssmin' );
grunt.loadNpmTasks( 'grunt-contrib-concat' );
2019-02-23 01:00:47 +00:00
grunt.loadNpmTasks( 'grunt-contrib-copy' );
2014-02-02 21:33:20 +00:00
grunt.loadNpmTasks( 'grunt-contrib-watch' );
2014-02-10 12:52:41 +00:00
grunt.loadNpmTasks( 'grunt-contrib-clean' );
grunt.loadNpmTasks( 'grunt-newer' );
// Register tasks.
grunt.registerTask( 'default', [
'js',
'css'
]);
2016-01-22 19:42:05 +00:00
grunt.registerTask( 'js', [
'eslint',
'uglify:js_assets'
2016-01-22 19:42:05 +00:00
]);
grunt.registerTask( 'css', [
'sass',
'rtlcss',
2017-05-04 22:29:40 +00:00
'postcss',
'cssmin',
2017-05-04 22:29:40 +00:00
'concat'
]);
grunt.registerTask( 'assets', [
'js',
'css'
]);
grunt.registerTask( 'e2e-build', [
'uglify:js_assets',
'css'
]);
// Only an alias to 'default' task.
grunt.registerTask( 'dev', [
'default'
]);
};