Skip to content

Instantly share code, notes, and snippets.

@lukearmstrong
Last active December 17, 2015 14:49
Show Gist options
  • Save lukearmstrong/5627202 to your computer and use it in GitHub Desktop.
Save lukearmstrong/5627202 to your computer and use it in GitHub Desktop.
Trying to optimize all files loaded by app.js to app.min.js
|- public/
| |- js/
| | |- app/
| | | |- interactions.js
| | | |- main.js
| | | |- students.js
| | |- lib/
| | | |- console.log.js
| | | |- jquery-1.9.1.js
| | | |- no-js.js
| | | |- require.js
| | | |- typeahead.js
| | |- app.js
console.log('app.js loaded');
// Place third party dependencies in the lib folder
//
// Configure loading modules from the lib directory,
// except 'app' ones,
requirejs.config({
"baseUrl": "js/lib",
"paths" : {
"app" : "../app",
"jquery": "jquery-1.9.1"
},
"shim" : {
"no-js" : ["jquery"],
"typeahead": ["jquery"]
}
});
// Load the main app module to start the app
requirejs(["app/main"]);
define(["console.log", "jquery", "no-js", "typeahead"], function($) {
console.log('app/main.js loaded');
require([
"app/interactions",
"app/students"
]);
});
// It is working in the browser, because in each file I have a console.log()
// Console Output:
lib/require.js loaded require.js:1
app.js loaded app.js:1
lib/console.log.js loaded console.log.js:24
lib/jquery-1.9.1.js loaded jquery-1.9.1.js:1
lib/no-js.js loaded no-js.js:1
app/main.js loaded main.js:3
app/interactions.js loaded interactions.js:1
app/students.js loaded students.js:1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment