dogbutcat / dracula

self-dev third generation tool

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Dracula

🧛Comes from 🏰 and 👿, it work as basic dev structure & simple api proxy.

CHANGELOG

2020/02

  • ADD server side rendering support
  • ADD log helper
  • ADD babel plugin for dynamic import and webpack plugin for manifest, thanks for @loadable

2019/07

  • UPDATE example project & some webpack configure

2019/05

  • ADD MIT license
  • UPDATE bundler version to webpack 4.x, babel 7.x
  • UPDATE install package process check function to npm search
  • UPDATE server side rendering
  • UPDATE default babel loader support .babelrc

2019/04

  • ADD auto install package webpack plugin
  • UPDATE webpack bundler from main to child process
  • UPDATE auto refresh server config under dev mode

Getting Started

  1. 新建一个git空项目
  2. 执行命令 git submodule add [git-http/ssh] lib
  3. 运行git submodule init && git submodule update
  4. 执行cp -rf ./lib/example/* .
  5. 生成的lib目录请勿随意更改,如果需要更新库代码请执行以下代码npm run libgit submodule update -f && git submodule foreach git pull origin [branch]
  6. 更新后的lib引用切记同步到git
  7. 执行npm install
  8. 请进入src目录开发
  9. 启动开发模式npm start
  10. 启动上线模式npm run build 默认输出目录为 ./public/project/, 如需更改请修改dracula.config.js中的output

内置工具引用方法

Deprecated
import { HttpTool } from './lib/utils'

或者

import { utils } from './lib';

let HttpTool = utils.HttpTool

HttpTool API

  • typeEnum

    Enum object, current is { POST: 'post', GET: 'get', PUT: 'put', DELETE: 'delete' }

  • request

    Function(type, api_type, successCallback, failCallback, param, reqOptions), type is value lists in typeEnum.

    • reqOption is extra options pass to backend server, current support {isFormData,isRefer,ipKey}
      • isFormData(boolean) param need to construct to meet application/x-www-form-urlencoded requirment
      • isRefer(boolean) api_type arg can contain 'http(s)://' to request
      • ipKey(string) use value with target key lists in server config of dracula.config.js, value format refers to serviceIP

Attention

if you don't want to define request `type` in request, you can use `HttpTool.post` or `HttpTool.get`...with same arguments follow which list in typeEnum object.

CookieHelp API

  • saveUserInfo

    Function(userinfo, save, keyName), set userinfo according to keyName, if not given use default user key 'DEMON_USER' in helper, save means cookie expired in how many days.

  • getUserInfo

    Function(keyName?), get user info according to keyName from cookie, if not given keyName in first time, use default user key 'DEMON_USER' in helper or it will use the value when call saveUserInfo above.

  • cleareUserInfo

    Function(), clear user info in cookie, no matter it exists or not.

  • getCookieInfo

    Function(cookieKey), get cookie value according to cookie key, return null if not exists, or return string or JSON data.

  • saveCookieInfo

    Function(key, value, time), save cookie value with key, value and expire time.

  • clearCookie

    Function(), clear all cookie.

dracula.config.js Config File Keywords

server

express config options

DEV (Boolean)

DEV property is set server whether running under DEV mode, true means dev mode, default: true

manifestPath (String)

manifestPath means the file path which bundled resources for web, main for filter out which dynamic import chunks will be loaded and told browser which chunks should be waiting before load content.

ipPass (Object)

set debug ip pass configuration

type (String)

type property is used to set ip pass type, query and path

  • query means debug ip passed through url parameters, eg. http://localhost:3000/?ip=192.168.1.1:8008
  • path means debug ip passed through path, eg. http://localhost:3000/192.168.1.1:8008/

queryKey (String)

queryKey property is to set what key value to parse the debug ip, default is ip, eg. http://localhost:3000/?ip=192.168.1.1:8008, it will not work with type above with value 'path'

serviceIP (String)

serviceIP property is set target server, can be changed when in dev mode and address followed with address[:port], default: 10.0.0.182:9092

addrMap (Object)

addrMap property is the object with key: [...] to set address mapping for visiting address directly, and key value MUST start with type of http or https eg.

when you visiting the website, its address is http://www.example.com/visit, and set addrMap property with object like this: {"http://127.0.0.1":["http://www.example.com", "http://localhost:3000"]}, then transfer Host will set to its key [in this example is http://127.0.0.1], but when you visit the site of http://www.example2.com/search, it still transfer to default setting of serviceIP.

CAUSIONS

Addresses set need to include PORT and HTTP type, eg. if your object like {"http://127.0.0.1":["http://localhost"]}, it mean all visits from address of http://localhost like: http://localhost:3000, http://localhost:3001 will transfer to http://127.0.0.1, but https://localhost or http://127.0.0.1:3000 will not work

browserSupport (Number)

browserSupport property is used for set browser support with default IE version in number type, default: 8

blockPageName (String)

blockPageName property is set page path showing for browserSupport not passed, best for absolute path, default: hintPage.html

port (Number)

port property means port to run server, default: 3001

restfulSupport (Array[String])

restfulSupport property restrict which type of request type support by this server, if type not in array, use type index 0 of the array, default: ['post', 'get', 'put', 'delete']

viewPath (String)

viewPath property set the view path of express server

assetPath (String)

assetPath property set the static resources path of express server

acceptHeaders (Array[String])

acceptHeaders property is used to transfer the specific headers from client to back end server

contentEncoding (String)

contentEncoding property is used to set accept-encoding with target value,default is gzip, deflate, br, if don't need content compress set value to none to close it

custom (Object)

custom setting for server config include custom routes

serverRoutes (Function)

  • @params: req
  • @params: res
  • @params: next
  • @returns: void

serverRoutes is the function for custom express routes injection.

webpack

webpack config options

useBundle (Boolean)

which webpack version to use if install different versions in lib folder and outside, true means use inner webpack, default: true

dev (Object)

dev mode webpack options

useAnalyzer (Boolean)

enable webpack-bundle-analyzer in dev/release webpack config

config (Object)

assign this to replace partitial/total dev/release webpack config of preset webpack config

release (Object)

release mode webpack options

serverPack (Object)

additional webpack config for server side pack up like resolve or other.

TODO

  • Loader and Plugin extraction [2018-01-08]
  • Pack up [2018-01-08]
  • Auto install missing package under dev mode [2019-04-25]
  • Auto reload server setting under dev mode [2019-04-23]

About

self-dev third generation tool

License:MIT License


Languages

Language:HTML 78.6%Language:JavaScript 21.0%Language:CSS 0.3%