- 有时我们期望在前端开发时可以有以下功能集成
- 让项目迅速集成开发插件的功能
- 使用注解式路由
- 使用中间件
- 让你开发nodejs 项目与 前端项目习惯统一
- 数据模拟与真实请求快速无缝切换
so, let`s 安装吧:
npm install -S bitorjs
- 下面, 我们使用 bitorjs 开一个 vue 项目
- 使用 vue 官方脚手架 vue-cli 创建 项目
$ vue init webpack xxx
- 安装依赖
$ npm install -S bitorjs
$ npm install -S vuex vuex-persist
$ npm install -D babel-plugin-transform-decorators-legacy
// and add the following line to your .babelrc file:
{
"plugins": ["transform-decorators-legacy"]
}
-
创建 config/index.env.js
-
修改 src/main.js
// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import Application from 'bitorjs';
import App from './App'
Vue.config.productionTip = false
new Application({}, App, "#app").start(app => {
app.watch(require.context('../config', false, /.js$/))
app.watch(require.context('.', true, /^((?!/view/).)+.(vue|js)$/));
})
修改 router/index.js
import {
Get,
Controller
} from 'bitorjs'
import HelloWorld from '@/components/HelloWorld'
@Controller('/')
export default class {
@Get('/')
async index(ctx){
ctx.render(HelloWorld)
}
}
到此, 我们已开启了 bitorjs 之旅
上 一 篇: 前端库新作 Bitorjs 开源啦