UNPKG

akb-cli

Version:

akb cli

102 lines (88 loc) 2.21 kB
/** * @file edp-webserver-config.js * @author {%%{appName}%%} ({%%{email}%%}) * @description * */ 'use strict' var epr = require('edp-provider-rider'); var chokidar = require('chokidar'); var fs = require('fs'); var path = require('path'); exports.stylus = epr.stylus; // 默认配置 var stylusPlugin = epr.plugin(); // 端口 exports.port = 9091; // 静态文件根目录 exports.documentRoot = process.cwd() + '/public'; // 当路径为目录时,是否显示文件夹内文件列表 exports.directoryIndexes = true; var development = require('./config/server'); var server = { host: '127.0.0.1', port: development.port }; /* eslint-disable no-undef */ exports.getLocations = function () { return [ /* globals autocss */ { location: /\.css($|\?)/, handler: [ autocss({ stylus: { stylus: epr.stylus, use: stylusPlugin } }) ] }, /* globals html2js */ { location: /^[^\?]+?\.tpl\.js($|\?)/, handler: [ html2js() ] }, /* globals file */ { location: /^\/(assets|static)/, handler: [ file() ] }, /* globals proxy */ { location: /^.*$/, handler: [ proxy(server.host, server.port) ] } ]; }; /* eslint-enable no-undef */ exports.injectResource = function (res) { for (var key in res) { if (res.hasOwnProperty(key)) { global[key] = res[key]; } } }; // 需要监听并自动加载的文件 var watcherFile = ['app/controllers']; function hotreload(path) { if (path) { console.log('auto reload for ' + path); require.cache[path] = null; } } for (var i = 0; i < watcherFile.length; i++) { var watcher = chokidar.watch(path.resolve(__dirname, watcherFile[i])); watcher.on('change', hotreload); watcher.on('error', function (e) { console.error(e); }); } // 启动server require('./index');