代码拉取完成,页面将自动刷新
var opn = require('opn') // 打开浏览器
var path = require('path') // 路径模块
var express = require('express') // express框架
var webpack = require('webpack') //核心模块webpack
let chalk = require("chalk");
let ora = require("ora");
var net = require('net')
var package = require('./package.json')
var webpackConfig = require('./webpack.config')// 配置文件
var port = webpackConfig.devServer.port
var app = express()
var compiler = webpack(webpackConfig)
let FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin');
var devMiddleware = require('webpack-dev-middleware')(compiler, {
publicPath: webpackConfig.output.publicPath,
stats: "errors-only"
// quiet: true
})
var hotMiddleware = require('webpack-hot-middleware')(compiler, {
log: false,
heartbeat: 2000
})
// compiler.hooks.compile.tap('html-webpack-plugin', function (data, cb) {
// hotMiddleware.publish({ action: 'reload' })
// })
app.use(require('connect-history-api-fallback')())
//开启 支持history路由
app.use(devMiddleware) // 服务器webpack插件
app.use(hotMiddleware) // 热加载自动打包
app.use('/static', express.static('../static'))
var uri = 'http://localhost:' + port
var _resolve
// var readyPromise = new Promise(resolve => {
// _resolve = resolve
// })
devMiddleware.waitUntilValid(() => {
let spinner = ora();
spinner.succeed(chalk.green(`应用已启动:${webpackConfig.devServer.host}:${port}`))
spinner.succeed(chalk.green('欢迎使用 liu-cli --liuyong'))
webpackConfig.plugins.push(
new FriendlyErrorsWebpackPlugin({
compilationSuccessInfo: {
messages: [`应用已启动:${webpackConfig.devServer.host}:${port}`],
notes: ["欢迎使用 liu-cli --liuyong"],
},
})
);
if (process.env.NODE_ENV !== 'testing') {
opn(uri)
}
})
var server = app.listen(port,function(){
let spinner = ora();
spinner.succeed(chalk.green(`start dev server success`))
})
module.exports = {
close: () => {
server.close()
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。