-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create shared lib for common assets #93
Comments
Yeah ok I made a mess. Let's not dwell on it. |
An idea to consider eventually, would be to use a package manager to handle libraries - and programmatically call it behind the scenes when starting the application in development mode. In my own applications I have something along the lines of: // index.js
// Sets the environment to `development`, unless otherwise specified.
var env = (process.env.NODE_ENV || (process.env.NODE_ENV = 'development'));
var when = require('when');
var gruntCompile = function () {
var dfd = when.defer();
var spawn = require('child_process').spawn;
spawn('grunt')
.on('error', function(e) {
dfd.reject(e);
})
.on('exit', function () {
dfd.resolve('Grunting Complete!');
});
return dfd.promise;
};
// Grabs & Compiles the assets to run in the app.
var assetFetch = function () {
var dfd = when.defer();
var _ = require('underscore');
var bower = require('bower');
var componentsJson = require('./bower.json');
var componentsDir = fs.readdirSync('./components');
if (_.keys(componentsJson.dependencies).length !== componentsDir.length) {
console.log('Installing Updated Bower Components, please wait.');
bower.commands
.install()
.on('end', function() {
console.log('Finished Bower install.');
dfd.resolve(gruntCompile());
})
.on('error', function (e) {
dfd.reject(e);
});
} else {
dfd.resolve(gruntCompile());
}
return dfd.promise;
};
when((env === 'development' ? assetFetch() : true)).then(function() {
require('./app');
}, function(e) {
console.log(e.stack);
}); Where the bower installs all the necessary scripts from This is really quickly hacked together for my own purposes, but a more refined version of something like this could be really nice for clean dependency management and not including these files in version control or needing them in any specific directory to add them to a single file - we could specify a structure for developers to add assets that would be brought into the build system when the app starts. |
Looks like my comment disappeared. Either bower or a variation of
|
Right, it'd could be a grunt task that you ran on app initialization (so you didn't have to remember to run grunt from the cli)... nothing we need to do for now though. |
What's the status of this, is there a consensus on what is needed to be done? |
|
The shared libraries should absolutely live in /core/shared. There are several we can share inc jQuery, underscore, moment, handlebars. I would also like to look into sharing handlebars helpers between client and server - though I'm not sure how to do that and I will put that in a separate issue. I want to make the best use of tools available like bower and grunt. I do think that this should be a grunt task - preferably part of |
@jgable @tgriesser @ricardobeat anyone wanna call dibs on this one? |
o/ On Tue, Jul 16, 2013 at 1:03 PM, Hannah Wolfe notifications@github.com
|
Are we going to use Should shared libs go in |
Yes, This issue refers to 3rd party libraries like jQuery, underscore & backbone only, and they should live in I'm not sure what you mean about moving |
oh, failed pull. now i got it 😍 |
At the moment jQuery lives in
core > client > assets > vendor > jquery > jquery.min.js
This isn't particularly useful - because with an incredibly common library like jQuery what we really want is to have it in a shared location where it can be used by both admin, as well as themes/plugins - both front and back end. (ala wp_enqueue_script)
There are several assets which this workflow applies to - so this probably needs to be properly considered / worked into the structure of the app.
The text was updated successfully, but these errors were encountered: