this article introduces how to concatenate, compress your seajs projects in product environment.
Install the nodejs/npm
see ref:
https://github.com/joyent/node/wiki/Installation
http://joyeur.com/2010/12/10/installing-node-and-npm/
https://gist.github.com/579814
Installing the spm
npm install spm -g
npm install spm-build -g
after install spm, exporting the variable NODE_PATH on the demand of spm, note it's the path that contain spm rather than nodejs on your platform. after installing spm, you can type spm and just follow the tip.
upload your project
upload your project to the server by whatever means.
setup your environment for grunt
a. install grunt CLI
#uninstall globally installed grunt before manipluate your project, we do our stuff under our project folder we upload;
#npm uninstall -g grunt
npm install -g grunt-cli
the functionality of grunt-cli is to search which version of grunt should run, it allow multiple version of grunt be installed on system; when node's require() get called, grunt-cli make user able to run grunt from any subfolder of ur project. the specific imple for grunt-cli is https://github.com/gruntjs/grunt-cli/blob/master/bin/grunt.
b. installing grunt
installing the grunt under your project folder:
# or u can do this step in d step with --save-dev option after building the package.json and Gruntfile.js
npm install grunt
c. setup the package.json and Gruntfile.js
package.js is the file needed by npm. you have to list the grunt plugins installed in 'devDependencies' in the file.
Gruntfile.js is used to define and configure tasks.
grunt-init create a project specific package.json. npm init will create a basic package.json;
d. installing the grunt plugin that spm build need.
according to the sample provied by seajs.org, hello sample:https://github.com/seajs/examples/blob/master/static/hello/Gruntfile.js
so install these 4 plugins under project root folder, it's where your uploaded project root folder is.
npm install grunt --save-dev
npm install grunt-cmd-transport --save-dev
npm install grunt-cmd-concat --save-dev
npm install grunt-contrib-uglify --save-dev
npm install grunt-contrib-clean --save-dev
note, using --save-dev option will writing the plugin info into your package.json's devDependencies section. you don't need edit it manually.
Setting up your Gruntfile.js
ref:Getting started: http://gruntjs.com/getting-started
Sample Gruntfile: http://gruntjs.com/sample-gruntfile
Configuring tasks: http://gruntjs.com/configuring-tasks
I think these 3 articles is a must to read before your tackling the project.
it's the grunt-cmd-transport plugin that actually extract the id from each module file your have written in your seajs projects, converting the module's define function into the 3-param form of it. see why there is need to extract id here: https://github.com/seajs/seajs/issues/426;
concat : combine all js file, producing one source file and one debug-src file;
uglify: compress js.
I made some small fix to the hello sample Gruntfile.js and grunt-cmd-transport plugin proviede by seajs.org, otherwise the build will not success.