Created
August 5, 2016 08:42
-
-
Save Phil23/77b9438741e4325899adcc5ccfe77930 to your computer and use it in GitHub Desktop.
A test for an alternate gruntfile for Shopware to override LESS variables locally.
This file contains 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) { | |
var shopId = grunt.option('shopId') || 1, | |
file = '../web/cache/config_' + shopId + '.json', | |
config = grunt.file.readJSON(file), | |
lessTargetFile = {}, | |
jsFiles = [], | |
jsTargetFile = {}, | |
content = ''; | |
lessTargetFile['../' + config.lessTarget] = '../web/cache/all.less'; | |
config['js'].forEach(function (item) { | |
jsFiles.push('../' + item); | |
}); | |
jsTargetFile['../' + config.jsTarget] = jsFiles; | |
for (var key in config.config) { | |
content += '@' + key + ': ' + config.config[key] + ';'; | |
content += '\n'; | |
} | |
config['less'].forEach(function (item) { | |
content += '@import "../' + item + '";'; | |
content += "\n"; | |
}); | |
grunt.file.write('../web/cache/all.less', content); | |
grunt.initConfig({ | |
uglify: { | |
production: { | |
options: { | |
compress: true, | |
preserveComments: false | |
}, | |
files: jsTargetFile | |
}, | |
development: { | |
options: { | |
mangle: false, | |
compress: false, | |
beautify: true, | |
preserveComments: 'all' | |
}, | |
files: jsTargetFile | |
} | |
}, | |
less: { | |
production: { | |
options: { | |
compress: true, | |
relativeUrls: true | |
}, | |
files: lessTargetFile | |
}, | |
development: { | |
options: { | |
dumpLineNumbers: 'all', | |
relativeUrls: true, | |
sourceMap: true, | |
sourceMapFileInline: true, | |
sourceMapRootpath: '../' | |
}, | |
files: lessTargetFile | |
} | |
}, | |
watch: { | |
less: { | |
files: [ | |
'../engine/Shopware/Plugins/**/*.less', | |
'../themes/Frontend/**/*.less', | |
'../custom/plugins/**/*.less' | |
], | |
tasks: ['less:development'] | |
}, | |
js: { | |
files: [ | |
'../themes/Frontend/**/_public/src/js/*.js', | |
'../engine/Shopware/Plugins/**/frontend/**/src/js/**/*.js', | |
'../custom/plugins/**/frontend/**/src/js/**/*.js' | |
], | |
tasks: ['uglify:development'] | |
} | |
}, | |
jshint: { | |
options: { | |
browser: true, | |
force: true, | |
globals: { | |
jQuery: true, | |
StateManager: true | |
} | |
}, | |
src: [ | |
'Gruntfile.js', | |
'../themes/Frontend/**/_public/src/js/*.js', | |
'../engine/Shopware/Plugins/**/frontend/**/src/js/**/*.js' | |
] | |
} | |
}); | |
grunt.loadNpmTasks('grunt-contrib-less'); | |
grunt.loadNpmTasks('grunt-contrib-watch'); | |
grunt.loadNpmTasks('grunt-contrib-uglify'); | |
grunt.loadNpmTasks('grunt-contrib-jshint'); | |
grunt.registerTask('production', [ 'jshint', 'less:production', 'uglify:production' ]); | |
grunt.registerTask('default', [ 'less:development', 'uglify:development', 'watch' ]); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tested & approved.