purpose
my aim is these:i.when deploying a project, the js file's dependency can be dynamically and automatically managed, if this is not archived perfectly,at least there 's some shortcut to go;
ii. practical build method for seajs projects.
I' ve done a little exploration on the example provided seajs.org on their github, and also I 've read through the grunt website. i made some very small fix on Gruntfile.js and grunt-cmd-transport plugin in order to achive these above purpose. there are couple of artical talking about a dynamically dependency is encouraged, you can see this http://chaoskeh.com/blog/why-seajs.html
I wanna modify the sample by seajs.org in order to:
a. use dynamic file mapping of grunt so that i do need to point the file i'd like to build one by one.
b. base on the structure website, i wanna use only one global Gruntfile as configuration, i can use whatever folder sturcture to organize my js project, and each time i can select appropiate file to be built.
implementation
1. so i set Gruntfile as this:
grunt.initConfig({
transport: {
options: {
expand: true, // i add this property in order to set path correctly
// otherwise the dynamic file mapping(cwd) wouldn't success.
idleading : "dist/" // the place u wanna put the concat and compressed file. this property is treated as prefix rather than the property pointed by seajs.org.
},
hello:{
files: [
{
expand: true,
cwd: "js/",
src: ['jobs/hello/*.js', 'lib/json2.js','!jobs/hello/config.js'],
// u still have to edit the files u wanna include.
// what bring you convenvient is only the globbing and negate symbol can be used here,
// this is where i said in the beginning of this artical 'at least
//there is a shortcut to go'.
// based on what i understand to seajs, it's not the seajs who need this, but the grunt-cmd-transport need this to make a reference list to transform define function into the 3-param form. I don't know why, I think they should share the same file dependency analysis function module and manage it totally dynamically.
// but at least u can select the file among your projects rather than select them one by one as the hello world sample does.
dest: 'build/' } ] } },
.......
in grunt-cmd-transport plugin, i modify js tasks/transport.js line 85 as below. because I really dont know what built-in property can serve the same functionality.
destfile = path.join(fileObj.dest, options.expand?"":fname);
2.
note that the path that seajs.use use and the base value have to corporate with the path that you build and deploy the product js file.for example, in my example:
seajs.use("dist/jobs/hello/main");
//my base is :
seajs.config({ base: "mywebsite.com"}); //reset the base value to root of website
//rather than default value of seajs.
3. note, in my practice, windows version of grunt-cmd-transport will put \\ as delimitor of 3-param form in define function, which make the browser failed to load the js, u have to change it mannally. but in linux, there would not this problem.
i think the other stuff left are not much worth to interpret here, just read the grunt website.
I will upload my sample later.