diff --git a/Gruntfile.js b/Gruntfile.js index 65430f492..e5ffd7371 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -42,7 +42,8 @@ module.exports = function (grunt) { 'grunt-targethtml', 'grunt-usemin', 'grunt-cleanempty', - 'grunt-exec' + 'grunt-exec', + 'grunt-newer' ] }); @@ -219,7 +220,16 @@ module.exports = function (grunt) { } }, iframe: { - // Standalone dist/bramble.js iframe api + // Define files involved, so grunt-newer knows whether to re-build or not + files: { + 'dist/bramble.js': [ + 'src/bramble/client/**/*.js', + 'src/bramble/thirdparty/**/*.js', + 'src/bramble/ChannelUtils.js', + 'thirdparty/filer/dist/filer.min.js', + ] + }, + // Standalone, minified dist/bramble.js iframe api options: { name: 'thirdparty/almond', baseUrl: 'src', @@ -545,6 +555,11 @@ module.exports = function (grunt) { 'build-config' */ ]); + // task: build for development, skipping most steps: only build iframe API if needed. + grunt.registerTask('build-browser-dev', [ + 'newer:requirejs:iframe' + ]); + // task: build dist/ for browser grunt.registerTask('build-browser', [ 'build', diff --git a/README.md b/README.md index 9b45fbbd8..10cd354a8 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ The easiest way to run Bramble is to simply use: $ npm start ``` -This will generate the strings needed for localization in your `src/nls` folder and allow you to access Bramble on `localhost:8000`. You can terminate the server with `Ctrl+C` which will also clean up the strings that were generated in your `src/nls` folder. +This will generate the strings needed for localization in your `src/nls` folder and allow you to access Bramble on `localhost:8000` (NOTE: you need npm version 5 for the cleanup step to run properly; if it doesn't, use `npm run unlocalize` to restore the files in `src/nls/**/*`). It will also build the Bramble iframe API in dist/ if necessary. You can terminate the server with `Ctrl+C` which will also clean up the strings that were generated in your `src/nls` folder. If you want to simply run the server without the localized strings, run: diff --git a/package.json b/package.json index f85fe0420..48fcbf191 100644 --- a/package.json +++ b/package.json @@ -51,6 +51,7 @@ }, "devDependencies": { "bluebird": "^3.4.7", + "grunt-newer": "^1.3.0", "gunzip-maybe": "^1.3.1", "http-server": "mozilla/http-server#gzip", "mkdirp": "0.5.1", @@ -72,8 +73,8 @@ "production": "npm start -- --gzip", "test": "grunt test && grunt build-browser-compressed", "server": "http-server -p 8000 --cors", - "prestart": "npm run localize", - "start": "npm run server", + "prestart": "npm run localize && grunt build-browser-dev", + "start": "npm run server || true", "poststart": "npm run unlocalize" }, "license": "MIT" diff --git a/src/bramble/client/main.js b/src/bramble/client/main.js index 331718532..b55251481 100644 --- a/src/bramble/client/main.js +++ b/src/bramble/client/main.js @@ -29,7 +29,8 @@ require.config({ }); define([ - // Change this to filer vs. filer.min if you need to debug Filer + // NOTE: if you modify the files involved here, also change the requirejs:iframe files list in Gruntfile.js + // filer.min - change this to filer vs. filer.min if you need to debug Filer "thirdparty/filer/dist/filer.min", "bramble/ChannelUtils", "EventEmitter", diff --git a/src/hosted.js b/src/hosted.js index b0d54d675..3b99bb3d1 100644 --- a/src/hosted.js +++ b/src/hosted.js @@ -130,13 +130,19 @@ }); } - // Support loading from src/ or dist/ to make local dev easier - require(["bramble/client/main"], function(Bramble) { + // Support loading from src/ or dist/ (default) to make local dev easier + var isSrc = !!window.location.pathname.match(/\/src\/[^/]+$/); + var brambleModule; + + if(isSrc) { + console.log("Bramble src/ build"); + brambleModule = "../dist/bramble"; + } else { + console.log("Bramble dist/ build"); + brambleModule = "bramble"; + } + + require([brambleModule], function(Bramble) { load(Bramble); - }, function(err) { - console.log("Unable to load Bramble from src/, trying from dist/"); - require(["bramble"], function(Bramble) { - load(Bramble); - }); }); }());