Commit afdaccf6 authored by Gero Müller's avatar Gero Müller
Browse files

add require js optimization

parent 16d25736
appDir: 'vispa/static',
appDir: 'vispa',
mainConfigFile: 'vispa/static/js/config.js',
dir: 'build',
baseUrl: '.',
urlPrefix: '/assets/',
baseUrl: 'static',
wrapShim: true,
preserveLicenseComments: false,
useStrict: true,
wrap: false,
paths: {
'extensions/pscan': '/home/gmueller/Projects/pscan/pscan'
modules: [
//First set up the common build layer.
//module names are relative to baseUrl
name: 'vispa/config',
//List common dependencies here. Only need to list
//top level dependencies, "include" will find
//nested dependencies.
include: ['jclass',
include: ['vispa/common/url', 'vispa/common/dialog', 'emitter', 'jclass']
//Now set up a build layer for each main layer, but exclude
//the common one. "exclude" will exclude nested
//the nested, built dependencies from "common". Any
//"exclude" that includes built modules should be
//listed before the build layer that wants to exclude it.
//The "page1" and "page2" modules are **not** the targets of
//the optimization, because shim config is in play, and
//shimmed dependencies need to maintain their load order.
//In this example, common.js will hold jquery, so backbone
//needs to be delayed from loading until common.js finishes.
//That loading sequence is controlled in page1.html.
//module names are relative to baseUrl/paths config
name: 'vispa/password',
exclude: ['vispa/config']
//module names are relative to baseUrl
name: 'vispa/login',
exclude: ['vispa/config']
//module names are relative to baseUrl
name: 'vispa/vispa',
include: ['vispa/views/dialog'],
exclude: ['vispa/config']
name: 'extensions/file/static/js/extension',
exclude: ['vispa/config', 'vispa/vispa']
name: 'extensions/codeeditor/static/js/extension',
exclude: ['vispa/config', 'vispa/vispa', 'ace/ace', 'ace/ext-language_tools']
name: 'extensions/terminal/static/js/extension',
exclude: ['vispa/config', 'vispa/vispa']
\ No newline at end of file
......@@ -22,8 +22,11 @@ dev_mode = True
# use base when running in subdirectory
base = /vispa
# set dynamic part seperatly
#base.dynamic = /vispa
#base.static = http://localhost:8080/
#base_dynamic = /vispa
#base_static = http://localhost:8080/
# build path for or.js optiomized build files. absolute, or relative to vispa package folder.
#build_path = ../build
# logging on client side
logging.level = all
......@@ -2,6 +2,45 @@
Deployment Guide
Optimized Static Resource
VISPA uses require.js to load JavaScript, CSS and Template files. In normal or development mode each file is loaded dynamically using the AMD loader. Since the VISPA frontend consists of many files, this i quite some overhead.
Require.js provides the means to merge and minify all the files using the r.js optimizer.
The basic idea is to provide the optimized files instead of the original files, so not path or other flags need to be changed.
.. note::
The optimizer currently requires that all extensions are placed in the vispa/extensions folder. Symlinks are possible though.
The following steps are required to use optimized builds in VISPA:
#. Install the npm packages:
.. code-block:: bash
$ npm install
#. Add all extensions that shall be optimized in build.js. Add another module, like the filebrowser extension:
.. code-block:: js
name: 'extensions/file/static/js/extension',
exclude: ['vispa/config', 'vispa/vispa']
#. Run the optimizer. All static files are copied to the build folder.
.. code-block:: bash
$ node_modules/.bin/r.js -o build.js
#. Set the build_path variable in the [web] section in the vispa.ini. Use a relative path to the vispa package folder or an absolute path.
.. code-block:: ini
build_path = ../build
Upgrade the Database
......@@ -35,5 +74,5 @@ Now you can use the alembic tool to migrate the database:
.. code-block:: bash
alembic -c vispa.ini upgrade head
$ alembic -c vispa.ini upgrade head
......@@ -55,13 +55,23 @@ class AbstractController(object):
def mount_static(self, path=None, url='static'):
if path and not os.path.isabs(path):
path = os.path.join(os.path.dirname(inspect.getabsfile(self.__class__)), path)
elif not path:
path = os.path.join(os.path.dirname(inspect.getabsfile(self.__class__)), 'static')
path = path or 'static'
static_path = os.path.join(os.path.dirname(inspect.getabsfile(self.__class__)), path)
build_path = vispa.config("web", "build_path", None)
if build_path:
self_path = os.path.dirname(inspect.getabsfile(self.__class__))
vispa_path = os.path.dirname(inspect.getabsfile(vispa))
build_path = os.path.join(vispa_path, build_path)
if self_path.startswith(vispa_path):
self_path = self_path[len(vispa_path)+1:]
build_path = os.path.join(build_path, self_path, path)
if not os.path.isdir(build_path):
logger.warning("Controller: build_path '%s' not found, fallback to default.", build_path)
static_path = build_path"Mount static controller. path: %s, url: %s" % (path, url))
setattr(self, url, StaticController(path))"Mount static controller. path: %s, url: %s" % (static_path, url))
setattr(self, url, StaticController(static_path))
# a little helper
def get(self, key, *args, **kwargs):
......@@ -35,7 +35,15 @@ class RootController(AbstractController):
self._server = server
self.mount_static(os.path.join(os.path.dirname(inspect.getabsfile(vispa)), 'static'))
static_path = os.path.join(os.path.dirname(inspect.getabsfile(vispa)), 'static')
build_path = vispa.config("web", "build_path", None)
if build_path:
build_path = os.path.join(os.path.dirname(inspect.getabsfile(vispa)), build_path, 'static')
if not os.path.isdir(build_path):
logger.warning("RootController: build_path '%s' not found, falling back to default.", build_path)
static_path = build_path
self.ajax = AjaxController(self)
self.fs = FSController()
self.extensions = AbstractController(mount_static=False)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment