This is a proposal to simplify our frontend setup.
The current frontend setup has some cognitive overhead in how we use it.
Problems:
- Using third-party components is not straight forward.
- Have to remember what bower installs to
public/client/bower_components/
- What is the relation of
client/
andpublic/client/
? - How do we
require
a bower component?
- Working with JS templates is not straight forward.
- Where do I write my application templates?
- How do I
require
templates for my app? (Backbone and Angular)
client/
common/
desktop/
app/
inbound_stock_transfer_order/
templates/ # Contains Angular partials
app.js
require.config.js
...
...
...
mobile/
...
public/
client/
app/ # Copied from client/ folder via gulp
common/
desktop/
app/
inbound_stock_transfer_order/
mobile/
isto-templates.js # Compiled from client/desktop/app/inbound_stock_transfer_order/templates/
...
bower_components/ # Third-party components
angular/
...
client-built/ # Compiled from public/client
Notes:
- To use third-party components, you must require from
../bower_components
because it is one directory up from RequireJSbaseUrl
. This is weird, and is partly why we reconfigure paths usingrequire.config()
. client/
gets copied topublic/client/app/
, which makes paths harder to understand. (e.g.public/client/app/desktop/app
)- To
require
a template, you must use the name configured withinclient/modules.json
. e.g. for ISTO it isrequire(['isto-templates'])
.
client/
bower_components/ # bower_components is now within client folder
common/
desktop/
app/
inbound_stock_transfer_order/
templates/
app.js
require.config.js
...
mobile/
...
public/
client/ # Moved from public/client/app to public/client
desktop/
app/
inbound_stock_transfer_order/ # Same as before but includes templates.js so path matches source
app.js
require.config.js
templates.js
...
client-built/
Notes:
- All JS modules are now served from
baseUrl
(public/client
), and we no longer need to go one directory up.- Paths are easier to reason about, because
client/
contains all modules needed.
- Paths are easier to reason about, because
- We will need to copy
bower_components/**/*.js
fromclient/
topublic/client
. - Template path now matches source. e.g.
require(['desktop/app/inbound_stock_transfer_order/templates'])
.
Current benchmarks:
gulp watch
takes 15 seconds to startup.gulp watch
uses up 100 MB of memory on startup.gulp watch
uses up 200 MB of memory once warmed up (after ~10-15 JS changes).