Skip to content
This repository has been archived by the owner on May 24, 2023. It is now read-only.

Commit

Permalink
openui5_connect: inject additional livereload plugin
Browse files Browse the repository at this point in the history
The plugin will handle the case when a .less file got changed but only
.css files are in the browser (server-side less compilation). It will
now reload all css files instead of reloading the complete page
  • Loading branch information
matz3 committed Nov 21, 2014
1 parent 976a273 commit 20225e8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@
},
"dependencies": {
"async": "^0.9.0",
"connect-inject": "^0.3.2",
"connect-openui5": "^0.3.0",
"cors": "^2.0.0",
"less-openui5": "^0.1.1",
"multiline": "^1.0.1",
"object-assign": "^1.0.0",
"pretty-data": "^0.40.0",
"uglify-js": "^2.4.15",
Expand Down
42 changes: 42 additions & 0 deletions tasks/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,38 @@
var openui5 = {
connect: require('connect-openui5')
};
var inject = require('connect-inject');
var cors = require('cors');
var urljoin = require('url-join');
var multiline = require('multiline');

var liveReloadLessCssPlugin = multiline(function() {/*
var LiveReloadPluginLessCss = function(window, host) {
this.window = window;
this.host = host;
};
LiveReloadPluginLessCss.identifier = 'less_css';
LiveReloadPluginLessCss.version = '1.0';
LiveReloadPluginLessCss.prototype.reload = function(path, options) {
// do only run this if less is not loaded (LiveReload LessPlugin will handle this)
if (!this.window.less) {
// reload stylesheets (css) also if a less file was changed
if (path.match(/\.less$/i)) {
return this.window.LiveReload.reloader.reloadStylesheet(path);
}
if (options.originalPath.match(/\.less$/i)) {
return this.window.LiveReload.reloader.reloadStylesheet(options.originalPath);
}
}
return false;
};
LiveReloadPluginLessCss.prototype.analyze = function() {
// disable the plugin if less is loaded (LiveReload LessPlugin will handle this)
return {
disable: (this.window.less && this.window.less.refresh)
};
};
*/});

module.exports = function(grunt, config) {

Expand Down Expand Up @@ -70,6 +100,18 @@ module.exports = function(grunt, config) {
};
}

// handle livereload option including css/less files (reload css if less files got changed)
if (connectOptions.livereload !== false) {
var port = (connectOptions.livereload === true) ? 35729 : connectOptions.livereload;
connectOptions.livereload = false; // prevent grunt-contrib-connect from inserting the livereload script
mountMiddleware(inject({
snippet: [
'\n<script>//<![CDATA[\n' + liveReloadLessCssPlugin + '\n//]]></script>\n',
'\n<script>//<![CDATA[\ndocument.write("<script src=\'//" + (location.hostname || "localhost") + ":' + port + '/livereload.js?snipver=1\'><\\/script>")\n//]]></script>\n'
]
}));
}

// fix serving *.properties files (encoding)
mountMiddleware(openui5.connect.properties());

Expand Down

0 comments on commit 20225e8

Please sign in to comment.