Skip to content

Instantly share code, notes, and snippets.

@shyim
Last active November 27, 2018 11:05
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save shyim/12c2b2db6b939748c54b to your computer and use it in GitHub Desktop.
Save shyim/12c2b2db6b939748c54b to your computer and use it in GitHub Desktop.
Gulp Shopware with browser-sync
function basename(path) {
return path.split('/').reverse()[0];
}
var gulp = require('gulp'),
less = require('gulp-less'),
concat = require('gulp-concat'),
rename = require('gulp-rename'),
path = require('path'),
fs = require('fs'),
watch = require('gulp-watch'),
browserSync = require('browser-sync').create(),
file = '../web/cache/config_1.json',
config = JSON.parse(fs.readFileSync(file)),
jsFiles = [],
jsTargetFile = {},
content = '',
variables = {
'font-directory': '"../../themes/Frontend/Responsive/frontend/_public/src/fonts"',
'OpenSansPath': '"../../themes/Frontend/Responsive/frontend/_public/vendors/fonts/open-sans-fontface"'
};
config['js'].forEach(function(item) {
jsFiles.push('../' + item);
});
jsTargetFile['../' + config.jsTarget] = jsFiles;
config['less'].forEach(function(item) {
content += '@import "../' + item + '";';
content += "\n";
});
fs.writeFileSync('../web/cache/all.less', content);
for (var key in config.config) {
variables[key] = config.config[key];
}
gulp.task('less', function() {
return gulp.src('../web/cache/all.less')
.pipe(less({
modifyVars: variables,
paths: [path.join(__dirname, 'less', 'includes')],
relativeUrls: true
}))
.pipe(rename(basename(config.lessTarget)))
.pipe(gulp.dest('../web/cache'));
});
gulp.task('js', function() {
return gulp.src(jsFiles)
.pipe(concat(basename(config.jsTarget, {
newLine: ';'
})))
.pipe(gulp.dest('../web/cache'));
});
gulp.task('default', ['less', 'js'], function() {
gulp.watch(['../themes/Frontend/**/_public/src/js/*.js', '../engine/Shopware/Plugins/**/frontend/**/src/js/**/*.js'], ['js']);
gulp.watch(['../engine/Shopware/Plugins/**/*.less', '../themes/Frontend/**/*.less'], ['less']);
browserSync.init();
gulp.watch("../web/cache/*.css").on('change', browserSync.reload);
gulp.watch("../web/cache/*.js").on('change', browserSync.reload);
});
{
"name": "gulp-sw",
"version": "1.0.0",
"description": "",
"main": "Gulpfile.js",
"dependencies": {
"browser-sync": "^2.10.0",
"gulp": "^3.9.0",
"gulp-concat": "^2.6.0",
"gulp-less": "^3.0.3",
"gulp-rename": "^1.2.2",
"gulp-watch": "^4.3.5"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "shyim",
"license": "ISC"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment