1 Star 0 Fork 1

Eminoda/ssr-learn

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
koawebpackApp.js 1.10 KB
一键复制 编辑 原始数据 按行查看 历史
Eminoda 提交于 6年前 . update #
const Koa = require('koa');
const path = require('path');
const webpack = require('webpack');
const koaWebpack = require('koa-webpack');
const app = new Koa();
const clientConfig = require('./build/webpack.client.config');
// koa-webpack 自动添加
clientConfig.entry.app = [clientConfig.entry.app];
clientConfig.output.filename = '[name].js';
clientConfig.plugins.push(new webpack.NoEmitOnErrorsPlugin());
const clientCompiler = webpack(clientConfig);
function ready(options) {
return koaWebpack(options);
}
let koaWebpackOptions = {
compiler: clientCompiler,
devMiddleware: {}
};
ready(koaWebpackOptions).then(koaWebpackMiddleware => {
app.use(koaWebpackMiddleware);
app.use(async (ctx, next) => {
if ((ctx.request.path = '/')) {
const filename = path.resolve(clientConfig.output.path, 'index.html');
ctx.response.type = 'html';
ctx.response.body = await koaWebpackMiddleware.devMiddleware.fileSystem.createReadStream(filename);
} else {
await next();
}
});
app.listen(3000, () => {
console.log('server is started on 3000 port ', 'http://127.0.0.1:3000');
});
});
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/eminoda/ssr-learn.git
git@gitee.com:eminoda/ssr-learn.git
eminoda
ssr-learn
ssr-learn
webpack-server-koa

搜索帮助