node-cube
Advanced tools
Comparing version 0.0.1-pre to 0.0.1-pre2
26
index.js
@@ -12,2 +12,4 @@ /*! | ||
var LessProcessor = require('./controller/less_processor'); | ||
var JsTransfer = require('./lib/jstransfer'); | ||
var CssTransfer = require('./lib/csscombine'); | ||
var app; | ||
@@ -20,5 +22,3 @@ /** | ||
* - root static root | ||
* - match http path | ||
* - jsdir js dir name | ||
* - cssdir css dir name | ||
* - router http path | ||
*/ | ||
@@ -35,3 +35,3 @@ exports.init = function (config) { | ||
app.use(connect.query()); | ||
app.use(config.match, function (req, res, next) { | ||
app.use(config.router, function (req, res, next) { | ||
var q = url.parse(req.url, true); | ||
@@ -58,3 +58,3 @@ var qpath = q.pathname; | ||
// other static files | ||
app.use(config.match, connect.static(config.root)); | ||
app.use(config.router, connect.static(config.root)); | ||
@@ -67,3 +67,3 @@ if (config.port) { | ||
console.log('[Cube] server started, listen:', config.port); | ||
console.log('[Cube] visit: http://localhost:' + config.port + path.join( config.match, '/index.html')); | ||
console.log('[Cube] visit: http://localhost:' + config.port + path.join( config.router, '/index.html')); | ||
} | ||
@@ -76,2 +76,16 @@ }); | ||
return app; | ||
}; | ||
exports.buildJs = function (file, base, compress) { | ||
JsTransfer.init(base); | ||
return JsTransfer.transferFile(file, compress); | ||
}; | ||
exports.buildTpl = function (file, base, compress) { | ||
}; | ||
exports.buildLess = function (file, base, compress) { | ||
}; | ||
exports.buildCss = function (file, compress) { | ||
return ; | ||
}; |
@@ -5,3 +5,3 @@ { | ||
"description": "a new way to write js in browser", | ||
"version": "0.0.1-pre", | ||
"version": "0.0.1-pre2", | ||
"homepage": "https://github.com/fishbar/cube", | ||
@@ -24,3 +24,3 @@ "repository": { | ||
"less" : "1.7.0", | ||
"xfs" : "0.1.7" | ||
"xfs" : "0.1.8" | ||
}, | ||
@@ -27,0 +27,0 @@ "devDependencies": { |
@@ -6,3 +6,3 @@ Cube | ||
像node.js一样编写浏览器端代码 | ||
像node.js一样编写浏览器端代码,无需争端AMD、还是CMD,只是build方式的不同,重要的是书写方便、简洁。 | ||
@@ -18,3 +18,3 @@ ## install | ||
每一个web应用都会包含这么一个目录叫静态资源, 比如: | ||
```sh | ||
@@ -28,10 +28,29 @@ webapp -| | ||
cube的初始化就从这个wwwroot开始, cube内建静态资源服务,启动服务: | ||
cube的初始化就从这个wwwroot开始,进入wwwroot目录,cube内建静态资源服务,启动服务: | ||
```sh | ||
# 初始化工程 | ||
cube init | ||
# 启动静态服务 | ||
cube run | ||
``` | ||
根据命令行提示的地址访问, ok,你的前端资源可以像node.js一样编写了 | ||
根据命令行提示的地址访问, ok,你的前端资源可以像node.js一样编写了。 | ||
在设计前端框架的时候,通常都会考虑到这点:前端资源需要可以被方便的部署到CDN等资源(动静态资源分离) | ||
cube的运行模式就是遵循这一设计思路的 | ||
## 集成到项目的connect中 | ||
假如你的工程已经是connect工程,或者express工程,那么可以很方便的将cube集成到工程中 | ||
```js | ||
var Cube = require('node-cube'); | ||
Cube.init({ | ||
root: '/wwwroot', // static resource path, like wwwwroot below | ||
app: app, // connect app object | ||
router: '/res/' // static resource url router | ||
}); | ||
``` | ||
ok, 访问你的调试环境 `http://localhost:port/res/xxx`, 静态资源+模块化支持 | ||
## 编写一个模块 | ||
@@ -56,2 +75,4 @@ | ||
引用现有的包, 你只需要 (a)编写好package依赖 (b) `npm install` (c) 像node一样引用这些模块 | ||
## 优化加载 | ||
@@ -58,0 +79,0 @@ |
Sorry, the diff of this file is not supported yet
95599
658
95