【发布时间】:2018-01-13 16:43:08
【问题描述】:
我有以下服务器代码:
var express = require('express');
var webpack = require('webpack');
var app = express();
//app.use(express.static(path.join(__dirname, "public")));
app.use("/", express.static(__dirname + "/public"));
//both not working. I have tried multiple ways....
app.get("/",function (req, res){
res.sendFile(__dirname + "/public/index/index.html")
});
app.listen(3000);
Webpack 配置
module.exports = {
entry: './app/index/index.js',
output: {
path: path.resolve(__dirname, 'public/index'),
publicPath: '/public/index',
filename: 'index_bundle.js'
},
module: {
rules: [
{ test: /\.(js)$/, use: 'babel-loader' },
{ test: /\.css$/, use: [ 'style-loader', 'css-loader' ]}
]
},
plugins: [
new HtmlWebpackPlugin({
template: 'app/index/index.html'
})
]};
以下目录结构:
-public
-index
-index_bundle.js
当我尝试加载我的 index_bundle js 时出现以下错误:
GET http://localhost:3000/public/index/index_bundle.js 404(未找到)
我无法修复它,我在网上找不到解决方案。
【问题讨论】:
-
是否有 index_bundle.js 所在的名为 index 的文件夹?
标签: node.js express webpack webpack-2 html-webpack-plugin