diff --git a/.gitignore b/.gitignore index 5bf8034..785d988 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,13 @@ .cubecache /node_modules /static -example.release +/example.release covreporter.html .idea/ -example.abs/ -example.out/ +/example.abs/ +/example.out/ /test_merge* /out/ -example/deps.release +/example/deps.release +/example/node_modules cube_info.*.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..53b26f1 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,27 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Debug Jsx", + "skipFiles": [ + "/**" + ], + "env": { + "DEBUG": "cube:*" + }, + "program": "${workspaceFolder}/bin/cube-start", + "args": [ + "/Users/fish/workspace/PDA/view/src", + "--no-cache" + ], + "outFiles": [ + "${workspaceFolder}/**/*.js" + ] + } + ] +} \ No newline at end of file diff --git a/README_NEW.md b/README_NEW.md new file mode 100644 index 0000000..6a77ba4 --- /dev/null +++ b/README_NEW.md @@ -0,0 +1,80 @@ +Cube +-------------- + +## Cube运行 + +### 独立Server运行 + +```sh +# 启动一个cube的dev服务,监听到指定端口 +cube run -p $port $static_root_path +``` +详细配置见下方 + +### Middleware集成 + +```js +const Cube = require('node-cube'); +// init cube middleware +let cubeMid = Cube.middleware(option); +// sample app +let app = Express(); +// mount middleware +app.use('/asset', cubeMid) +``` +详细配置见下方 + +### 构建目标代码 + +```sh +cube build $static_root_path -o $release_path +``` +详细配置见下方 + +## Cube配置 + +cube的配置,可以来自两个地方: +* 在静态资源根目录的package.json -> cube 属性中配置 <优先级高> +* 在代码中new Cube的时候传入的option对象 <优先级高> + +### option对象 + +```js +let option = { + // 前端资源的绝对文件路径 + rootPath: "", + // 前端资源的http访问的绝对路径(域名后完整的路径), 注意,在middleware模式确保访问路径对齐 + // 主要是css资源的处理 + httpPath: "", + // 各种类型的处理器 + processors: { + // multi ext to the same processor + ".js, .jsx, .ts, .tsx": "custom-processor", + // multi processors in serial + ".less": ["cube-less", "custom-css-processor"], + // ext to processors with config(if needed), the config is applied by the processor + ".less": [ + ["cube-less", {/* cube-less processor's config */}], + ["custom-css-processor", {/* custom processor plugin's config */}] + ] + }, + // 当前静态资源的命名空间,适用于多app的资源联合加载使用, ref to former opt.remote + namespace: "", +} +``` + +### Cube.Server(servOption) + +```js +Cube. +``` + + +### 定制processor + +cube支持4种类型的文件: + * script + * style + * json + + diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..fdc060c --- /dev/null +++ b/TODO.md @@ -0,0 +1,94 @@ + +## Interface升级 + +### 1. 客户端简化 + +html页面上直接引入entry文件即可: +```html + +``` +不在需要一个单独的cube文件 + +### 2. 服务端配置化 + +```js + +let cube = new Cube({ + /** + * 入口文件列表,从static file root开始算,绝对路径 + * @type {Array} + */ + entrys: [ + '/index.js' + ], + globalName: 'Cube', // default is cube + resourcePath: '/assets', // http加载的resoucepath + debug: true, + version: 12345 +}) + +// 挂载middleware +express.use('/assets', cube.service()); +``` +这些配置都可以编写在静态资源目录下的package.json - "cube" 下 + + +客户端访问路口文件时,会自动添加 cube.js, 以及启动入口。 + +这样对runtime的能力,可以做到插件化支持,还比较方便,同时入口维持和webpack类似 + +### cube_loader机制 + + +* 全局API +```js +// load modules +Cube($name,()=>{}) +Cube($name, [deps...], ()=>{}) + +// app entry +Cube.use($name, (app)=> { + app.run(); +}) +``` + +* 模块内API + +```js +module.exports + +exports + +import -> require + +export -> require + +async('module', (mod)=>{}) +``` + +* CSS加载支持 +转换成inline