如果我转到根目录localhost:8080,它会按照预期注入javascript;如果我转到localhost:8080/test,则会使用html -localhost plugin呈现html,但没有注入js
server.js
app.use('/', express.static(__dirname + '/dist'));
app.get('*', (req, res)=> {
res.sendFile(__dirname + '/dist/index.html');
});webpack.config.js
entry: [
"webpack-hot-middleware/client?reload=true",
"babel-polyfill",
path.resolve(__dirname, './config/app/app.js')
],
output: {
path: path.resolve(__dirname, './dist'),
filename: 'app.min.js',
publicPath: '/'
},
plugins: isDeveloping ? [
new HtmlWebpackPlugin({
hash: true,
filename: 'index.html',
template: __dirname + '/dist/index.html',
inject: 'body'
})我发现了一个与这个问题类似的问题,他们的解决方案是配置output.publicPath = '/‘,我这样做了,但仍然没有成功。我只是在没有注入JS的情况下获得模板
发布于 2017-08-06 08:05:35
原来我运行的是webpack-dev-server,它并没有注入到文件系统中。我把这个片段添加到我的webpack中,问题就解决了
"scripts": {
"start": "npm run build",
"build": "webpack -p && webpack-dev-server"
},https://stackoverflow.com/questions/45500038
复制相似问题