Sunley95
Sunley95

Reputation: 21

How to change Webpack-simple to Webpack in a Vue application?

I have created a vue application without realising that webpack-simple is unsuitable for deployment. Is there a way to change this to webpack without having to create a new project?

Thanks in advance.

Edit: Here is the server.js code where i think we are getting the error.

// server.js
const express = require('express');
const path = require('path');
const serveStatic = require('serve-static');

const app = express();
//app.use(serveStatic(path.join(__dirname + '/dist')));
app.use(serveStatic(path.resolve(__dirname, './dist/build.js')));

console.log("RESOLVED PATH " + path.resolve(__dirname, './dist/build.js'));

const port = process.env.PORT || 5000;
app.listen(port)

Upvotes: 0

Views: 479

Answers (2)

Sunley95
Sunley95

Reputation: 21

Got it working with a change to the script.js file.

This is the script.js file that worked in the end.

// server.js
const express = require('express');
const path = require('path');
const serveStatic = require('serve-static');

const app = express();
app.use(serveStatic(__dirname));

console.log("RESOLVED PATH " + path.join(__dirname, 'dist'));

const port = process.env.PORT || 5000;
app.listen(port);

console.log('server started '+ port);

The change that got it working was changing this line

app.use(serveStatic(path.resolve(__dirname, './dist/build.js')));

To this

app.use(serveStatic(__dirname));

Upvotes: 1

PlayMa256
PlayMa256

Reputation: 6831

Lets rework on top of what webpack-simple provides you.

You will need index.html and also the dist folder, closer to this server file.

const express = require('express');
const path = require('path');

const app = express();
app.use(express.static(path.resolve('.')));

app.all('*', (req, res) => {
  res.send('index.html');
})

const port = process.env.PORT || 5000;
app.listen(port)

Upvotes: 0

Related Questions