2017-08-04 17 views
0

使用HTML-的WebPack-插件 如果我去到根目录本地主机:8080它注入预期 如果我去本地主机的JavaScript:8080 /测试HTML渲染,但没有被JS注入html-webpack-plugin只在根路由中注入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 = '/',我没有,但ST生病没有运气。我刚刚得到没有注入JS的模板

回答

0

原来我正在运行webpack-dev-server,并且没有注入文件系统。我将这段代码添加到我的webpack并解决了问题

"scripts": { 
    "start": "npm run build", 
    "build": "webpack -p && webpack-dev-server" 
    },