Bolboa Bolboa - 2 months ago 7
Node.js Question

trying to render two different pages using two different entry points webpack

My webpack is partitioned to produce two outputs...

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

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


So one of my html file (login.html) will call...

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


And the other (index.html) calls...

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


Now each of these pages is a different route. Obviously
index.html
will be the main so in my server I did...

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


Everything renders find when I test it on local. But now I want to access the second
login.html
on a different route, I added this...

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


But when I go to
localhost:3000/login
I get this error...

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


The output is not found. Why is this so???

Answer

You configured your bundle for login.html to be named “a”, not “a.entry”. Try changing your script tag to:

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

(you don't need type="text/javascript" anymore in 2016)