- Generate a Sails project with
sails new your-app --no-frontend
- Install
express-vue
withnpm install express-vue --save
- Go to the view config of Sails app at
your-app/config/views.js
and replace theengine: 'ejs',
with this:
engine: {
ext: 'vue',
fn: (function() {
return require('express-vue');
})()
},
Also need to set the layout: 'layout',
to layout: false,
as it will be ignored by Sails anyway.
- Now we need to create
views
folder in the Sails app.mkdir your-app/views/ && touch your-app/views/homepage.vue
. Note, thatyour-app/config/routes.js
is already pointing the homepage-file to the localhost:1337/. - Edit the
homepage.vue
to add your Vue.js content to it, like:
<template>
<div>
<h1>Hello, world!</h1>
</div>
</template>
<script>
export default {
data() {
return {}
}
};
</script>
- After all, go to the
config/http.js
in your project. There will be themiddleware
object. You need to add thecustomMiddleware
function AFTER it, so everything looks like this:
module.exports.http = {
middleware: {
},
customMiddleware: function(app) {
app.set('vue', {
// configure express-vue here
// do not use __dirname here, otherwise the path will look like:
// /Users/username/your-project/config/components
// componentsDir: app.settings.views + '/components',
});
}
};
In version 4 of
express-vue
, this method results in the following:The
express-vue
docs now just sayBut there is no example of actually configuring
express-vue
in SailsJS. I have tried every combination of settings that I can think of in order to get something operational, but everything results in the above error. Any insight into this would be extremely valuable.My guess so far is that it has something to do with the configuration of the engine, as without it the system starts (but is unable to render anything).