Build the seajs project 2: editing the Gruntfile
来源:互联网 发布:怎么找文献的数据 编辑:程序博客网 时间:2024/05/01 19:09
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.
- Build the seajs project 2: editing the Gruntfile
- Build the seajs project1: preparation
- Building the Build System – Part 2 – Project Templates
- build the eclipse project of tucany sdo
- Editing with the geodatabase API
- The Project
- Build GUIs with the Eclipse Visual Editor project
- [转]The project was not built since its build path
- A cycle was detected in the build path of project
- 解决:The project cannot be built until build path
- A cycle was detected in the build path of project
- 解决:The project cannot be built until build path
- A cycle was detected in the build path of project
- A cycle was detected in the build path of project
- Open the Java build path property page of project
- “Open the Java build path Property page of project ''”
- A cycle was detected in the build path of project
- A cycle was detected in the build path of project
- socket编程中的超时设置示例详解之二
- WPF后台动态添加TabItem并设置样式
- INS-35354] The system on which you are attempting to install Oracle RAC is not part of a valid clust
- OpenGL入门(一)
- python实现SimpleHTTPServer的POST方法
- Build the seajs project 2: editing the Gruntfile
- ZOJ 2314 Reactor Cooling
- 漫谈JVM的基本垃圾回收算法
- Div+CSS+JS树型菜单
- 使用颜色(color)资源
- linux驱动学习--第一天:设备驱动概述(一)之基础知识
- 再论C++之垃圾回收(GC)
- 黑马程序员_Java基础Day13_String类(Done)
- IQ正交调制及星座图