加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
main.ts 1.98 KB
一键复制 编辑 原始数据 按行查看 历史
liuyong 提交于 2021-06-17 14:57 . 更新
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()
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化