Skip to content

Commit

Permalink
Bundle pump.js with Browserify
Browse files Browse the repository at this point in the history
See #301, but there's still more work to do.
  • Loading branch information
strugee committed Mar 15, 2018
1 parent 9ebbd1d commit b8fc65d
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
5 changes: 5 additions & 0 deletions lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ var urlparse = require("url").parse,
api = require("../routes/api"),
web = require("../routes/web"),
shared = require("../routes/shared"),
bundles = require("../routes/bundles"),
webfinger = require("../routes/webfinger"),
clientreg = require("../routes/clientreg"),
oauth = require("../routes/oauth"),
Expand Down Expand Up @@ -408,6 +409,10 @@ var makeApp = function(configBase, callback) {
hsts: config.hsts
}));

// This is done up here, instead of down there with the rest of the *.addRoutes(),
// because it has to override express.static()
bundles.addRoutes(app);

app.use(express.static(path.resolve(__dirname, "../public")));

// Default is in public/images/favicon.ico
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"dependencies": {
"bcryptjs": "^2.4.3",
"body-parser": "^1.15.2",
"browserify-middleware": "^8.1.0",
"bunyan": "^1.8.12",
"compression": "^1.6.2",
"connect-auth-pumpio": "^0.6.1",
Expand Down
7 changes: 7 additions & 0 deletions public/javascript/pump.js
Original file line number Diff line number Diff line change
Expand Up @@ -688,3 +688,10 @@ if (!window.Pump) {
};

})(window._, window.$, window.Backbone, window.Pump);

// XXX refactor these into *real* modules instead of just blindly including them
require("./pump/auth.js");
require("./pump/model.js");
require("./pump/router.js");
require("./pump/socket.js");
require("./pump/view.js");
5 changes: 0 additions & 5 deletions public/template/layout.jade
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,6 @@ html(lang="en")
script(src="/javascript/libs/bootstrap-lightbox.min.js")
script(src="/shared/jade-runtime.js")
script(src="/javascript/pump.js")
script(src="/javascript/pump/auth.js")
script(src="/javascript/pump/model.js")
script(src="/javascript/pump/router.js")
script(src="/javascript/pump/socket.js")
script(src="/javascript/pump/view.js")

each script in config.scripts
script(src="#{script}")
Expand Down
28 changes: 28 additions & 0 deletions routes/bundles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// bundles.js
//
// Serve up some sweet Browserify bundles
//
// Copyright 2018 AJ Jordan <alex@strugee.net>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

"use strict";

var browserify = require("browserify-middleware"),
path = require("path");

var addRoutes = function(app) {
app.get("/javascript/pump.js", browserify(path.join(__dirname, "../public/javascript/pump.js")));
};

exports.addRoutes = addRoutes;

0 comments on commit b8fc65d

Please sign in to comment.