Build the seajs project1: preparation

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.

that's all the step of preparation, see the second post blog:  Build the seajs project1: editing the Gruntfile

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值