var config = require('./config')
var path = require('path')
var webpack = require('webpack')
var webpackConfig = require('./webpack.dev.conf')
var compiler = webpack(webpackConfig)
//koa2
const Koa = require("koa")
const koaStatic = require("koa-static")
const koaWebpackMiddleware = require("koa-webpack")
const app = new Koa();
app.use(koaStatic(webpackConfig.output.publicPath));
app.use(koaStatic(webpackConfig.output.publicPath));
app.use(koaWebpackMiddleware({
compiler: compiler,
dev: {
publicPath: webpackConfig.output.publicPath,
headers: { 'Content-Type': 'text/html; charset=utf-8' },
stats: {
colors: true
},
serverSideRender: false
},
hot: {
log: console.log,
path: '/__webpack_hmr',
heartbeat: 10 * 1000
}
}))
// app.use(async (ctx, next) => {
// await next();
// console.log(ctx)
// if (!ctx.body && ctx.status == 404) {
// ctx.body = ctx.status;
// ctx.status = 404;
// }
// });
app.listen(8080, () => {});
在以上webpack中在/dist文件夹中编译出了一个文件 /dist/index.html
但是在访问 localhost:8080/dist/index.html的时候却返回not found,不知道我到底是少哪一步呢
最好贴一下webpack.dev.conf的配置文件,一般访问的时候不需要加/dist,具体可以参考一下我这里的配置:webpack.config.js