尝试使用两个不同的入口点webpack渲染两个不同的页面

时间:2016-10-09 18:12:24

标签: node.js reactjs webpack

我的webpack被分区以产生两个输出......

entry: {
    a: './src',
    b: './Authentication'
},

devtool: 'source-map',
  output: {
    path:'/',
    filename: 'scripts/[name].js',
    publicPath: '/'
},

所以我的一个html文件(login.html)会调用...

<script type="text/javascript" src='scripts/a.entry.js'></script>

另一个(index.html)调用...

<script type="text/javascript" src='./scripts/b.js'></script>

现在每个页面都是不同的路线。显然index.html将是我的服务器中的主要内容......

var path = require('path');
...
app.use(express.static(path.resolve('public')));
...
app.get('/', function(req, res){
    res.sendFile(path.resolve('public/index.html'));
});

当我在本地测试时,所有渲染都会找到。但现在我想在不同的路线上访问第二个login.html,我添加了这个......

app.get('/login', function (req, res) {
  res.sendFile(path.resolve('public/login.html'));
});

但是当我去localhost:3000/login时,我收到了这个错误......

GET http://localhost:3000/scripts/a.entry.js 404 (Not Found)

找不到输出。为什么这样呢???

1 个答案:

答案 0 :(得分:0)

您已将 login.html 的捆绑包配置为“a”,而不是“a.entry”。尝试将脚本标记更改为:

<script src='scripts/a.js'></script>

(2016年你不再需要 type =&#34; text / javascript&#34;