UNPKG

san-cli-docit

Version:

san-cli-docit 是 [San](https://github.com/baidu/san) CLI 工具中 Markdown 文档建站部分。 是一个 [command 插件](https://ecomfe.github.io/san-cli)。

70 lines (63 loc) 2.42 kB
/** * @file serve * @author ksky521 */ const {info, error} = require('san-cli-utils/ttyLogger'); module.exports = function serve(argv, api, projectOptions) { const mode = argv.mode; info(`Starting docit ${mode} server...`); const {publicPath} = projectOptions; const getNormalizeWebpackConfig = require('./getNormalizeWebpackConfig'); const webpackConfig = getNormalizeWebpackConfig(argv, api, projectOptions); const devServer = require('san-cli-webpack/serve'); devServer({ webpackConfig, publicPath, devServerConfig: webpackConfig.devServer }) .then(({isFirstCompile, networkUrl}) => { if (isFirstCompile) { const {textCommonColor} = require('san-cli-utils/color'); /* eslint-disable no-console */ console.log(); console.log(` Application is running at: ${textCommonColor(networkUrl)}`); console.log(' URL QRCode is: '); /* eslint-enable no-console */ // 打开浏览器地址 argv.open && require('opener')(networkUrl); if (argv.qrcode) { // 显示 terminal 二维码 require('qrcode-terminal').generate( networkUrl, { small: true }, qrcode => { // eslint-disable-next-line const q = ' ' + qrcode.split('\n').join('\n '); console.log(q); } ); } } }) .catch(({type, stats, err}) => { if (type === 'server') { error('Local server start fail!', err); } else if (stats && stats.toJson) { // // TODO: 这里删掉,调试用的 // process.stderr.write( // stats.toString({ // colors: true, // children: false, // modules: false, // chunkModules: false // }) // ); // const info = stats.toJson(); // error(info.errors); } else { error(err); } }); };