Skip to content

Commit

Permalink
Use npm and webpack to build GUI frontend.
Browse files Browse the repository at this point in the history
Previously, all of the JavaScript and CSS files that we wanted to
use in Nengo GUI had to be part of the source tree, and included
manually in a <script> or <link> tag in `page.html`. While this was
a good way to start out, as we grow it limits us to only using
pure JavaScript and CSS, and requires a cumbersome process to
upgrade our JS/CSS dependencies.

Now, we use npm to download specific versions of our frontend
dependencies, and webpack to bundle all of our dependencies and
our own frontend code together into a single bundle, which
greatly simplifies `page.html`.

Specifically, the frontend workflow now requires developers
to do the following actions once:

1. Install node.js, which should come with `npm`.
2. Run `npm install`.

Developers will now have all of the necessary dependencies
in the node_modules folder, which is now in .gitignore.

If developers are modifying or debugging frontend components,
then they should run the command:

   npm run build

which will package all of the frontend files into a non-minified
JS file (which includes all of the CSS), and produce a source map,
so that when debugging JavaScript files, the browser will show you
the original source file rather than the gigantic bundle.

If developers change any frotend files in a particular commit,
they should regenerate the "production" version of the bundle
that includes all of the frontend files. To do this, run:

   npm run release

which will package all the frontend files in a minimified and
optimized JS file. No source map will be produced. This keeps
the size of commits small while still enabling all commits to
be tested by CI.

For the time being, I have limited the changes required to get
npm + webpack working to the minimum number of files, which is
mainly nengo.js, which "imports" all of the other files.

Other changes:

- In netgraph.js, we no longer have a <link> tag to get a handle
  to; fortunately, it's possible to get the string version of the
  CSS through webpack, so now we use `require` to get the CSS.
- `data_to_csv.js` had to be modified to export the data_to_csv
  function because it's used in another file, and in tests.
- Moved the styles in `main.css` to `nengo.css`, as that's the
  entrypoint that we use anyhow.
  • Loading branch information
tbekolay committed Jul 14, 2016
1 parent 27090b8 commit 3c5c13b
Show file tree
Hide file tree
Showing 35 changed files with 300 additions and 6,436 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,6 @@ target/
# Vagrant
.vagrant
Vagrantfile

# Node JS stuff
node_modules/
2 changes: 1 addition & 1 deletion nengo_gui/static/ace.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Nengo.disable_editor = function() {
}

Nengo.Ace = function (uid, args) {
this.AceRange = ace.require('ace/range').Range;
this.AceRange = ace.Range;
if (uid[0] === '<') {
console.log("invalid uid for Ace: " + uid);
}
Expand Down
5 changes: 1 addition & 4 deletions nengo_gui/static/components/netgraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,7 @@ Nengo.NetGraph = function(parent, args) {
* this is needed for saving the SVG plot to disk*/

/** load contents of the CSS file as string */
var file = document.getElementById('netgraphcss');
var css = Array.prototype.map.call(file.sheet.cssRules, function
css_text(x) {return x.cssText; } ).join('\n');

var css = require('!!css-loader!./netgraph.css').toString();
/** embed CSS code into SVG tag */
var s = document.createElement('style');
s.setAttribute('type', 'text/css');
Expand Down
2 changes: 2 additions & 0 deletions nengo_gui/static/data_to_csv.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,5 @@ var data_to_csv = function(data_set){
return csv_string;

}

module.exports = data_to_csv;
Binary file added nengo_gui/static/dist/favicon.ico
Binary file not shown.
71 changes: 71 additions & 0 deletions nengo_gui/static/dist/nengo.js

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions nengo_gui/static/jquery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Loads jQuery and all of the plugins we use.
*
* Since jQuery plugins work by modifying the global variable $,
* we load up all of the plugins we use here so that we don't load
* plugins multiple times.
*/

var jQuery = require('jquery');

require('imports?$=jquery,jQuery=jquery!bootstrap');
require('imports?$=jquery,jQuery=jquery!bootstrap-validator');
require('imports?$=jquery,jQuery=jquery!jqueryfiletree/src/jQueryFileTree');
require('imports?$=jquery,jQuery=jquery!jquery-ui');

module.exports = jQuery;
5 changes: 0 additions & 5 deletions nengo_gui/static/lib/css/bootstrap.min.css

This file was deleted.

11 changes: 0 additions & 11 deletions nengo_gui/static/lib/js/ace-src-min/ace.js

This file was deleted.

5 changes: 0 additions & 5 deletions nengo_gui/static/lib/js/ace-src-min/ext-searchbox.js

This file was deleted.

1 change: 0 additions & 1 deletion nengo_gui/static/lib/js/ace-src-min/mode-python.js

This file was deleted.

7 changes: 0 additions & 7 deletions nengo_gui/static/lib/js/bootstrap.min.js

This file was deleted.

5 changes: 0 additions & 5 deletions nengo_gui/static/lib/js/d3.v3.min.js

This file was deleted.

Loading

0 comments on commit 3c5c13b

Please sign in to comment.