Skip to content

Instantly share code, notes, and snippets.

@mjot
Forked from shyim/Gulpfile.js
Last active October 25, 2017 08:35
Show Gist options
  • Save mjot/191edf134445af21d289b1efa6b0d555 to your computer and use it in GitHub Desktop.
Save mjot/191edf134445af21d289b1efa6b0d555 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'),
sourcemaps = require('gulp-sourcemaps');
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(sourcemaps.init())
.pipe(less({
modifyVars: variables,
paths: [path.join(__dirname, 'less', 'includes')],
relativeUrls: true
}))
.pipe(rename(basename(config.lessTarget)))
.pipe(sourcemaps.write('../'))
.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({
proxy: "shopware.dev"
});
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.18.13",
"gulp": "^3.9.1",
"gulp-concat": "^2.6.1",
"gulp-less": "^3.3.2",
"gulp-rename": "^1.2.2",
"gulp-sourcemaps": "^2.6.1",
"gulp-watch": "^4.3.11"
},
"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