我正在尝试从 reactjs 前端开始使用 feathersjs 应用程序。使用webpack-dev-middleware
and webpack-hot-middleware
,我应该能够在开发过程中使用所有这些 webpack 东西简单地扩展羽毛应用程序。唯一的问题是每当我从 webpack 获取 js 文件时,总是最终得到一个羽毛 404 页面。
目前,这是我的目录结构:
/feathers/public/index.html
/feathers/src/app.js
/react/src/index.js
/react/webpack.config.js
/react/develop.js
/feathers/src/app.js
is 是默认的羽毛应用程序,提供来自公共文件夹的静态文件。
.use('/', serveStatic( app.get('public') ))
在/react/develop.js
中,我需要羽毛应用程序并使用 webpack 中间件对其进行扩展。
const app = require('../feathers/src/app');
const config = require('./webpack.config');
const path = require('path');
const webpack = require('webpack');
var compiler = webpack(config);
app.use(require('webpack-dev-middleware')(compiler, {
publicPath: '/',
stats: {colors: true},
}));
app.use(require('webpack-hot-middleware')(compiler));
const port = app.get('port');
const server = app.listen(port);
server.on('listening', () =>
console.log(`Feathers application started on ${app.get('host')}:${port}`)
);
可悲的是,这根本不起作用。供参考,这是我的/react/webpack.config.js
var webpack = require("webpack")
module.exports = {
devtool: 'source-map',
entry: [
'webpack-hot-middleware/client',
'src/index.js'
],
output: {
path: '/',
filename: "bundle.js",
},
module: {
loaders: [
{ test: /\.js$/, loader: "babel", exclude: /node_modules/, query: { presets: ['es2015', 'react', 'stage-0'] } },
{ test: /\.(svg|png|jpe?g|gif|ttf|woff2?|eot)$/, loader: 'url?limit=8182' },
]
},
resolve: {
root: [
__dirname,
__dirname + '/src',
]
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
]
}
和/feathers/public/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>React App</title>
</head>
<body>
<div id="root"></div>
<script src="bundle.js"></script>
</body>
</html>
我试过弄乱 publicPath 的东西,但没有运气。任何想法如何让这个工作?我在这上面花了整整 2 个小时,却一无所获。这是我正在使用的 repo 的链接以获取更多上下文。