Install moleculer app using cli command:
npm install -g moleculer-cli
moleculer init project <project-name>
Install vuepress:
cd <project-name>
npm install vuepress --save-dev
Create moleculer mixin
// mixins/vuepress.js
const { createApp } = require( 'vuepress' );
const enabled = process.env.npm_lifecycle_event === 'dev';
let app;
let logger;
let server;
module.exports = {
settings: {
middleware: enabled,
...( enabled ? {} : {
assets: {
folder: './public/.vuepress/dist'
}
} )
},
async started(){
logger = this.broker.getLogger('Vuepress', { svc: 'Vuepress', ver: null });
if( enabled ){
const service = this;
app = createApp({
sourceDir: 'public',
port: this.settings.port,
host: this.settings.ip,
plugins: [[
( pluginOptions, context ) => ({
name: 'moleculer',
beforeDevServer(express, server) {
logger.info( `Connecting to vuepress dev server` );
express.use( service.express() );
}
})
]]
});
await app.process();
await app.dev();
}
}
}
Add vuepress mixin to API service before ApiGateway mixin:
// services/api.js
const ApiGateway = require( 'moleculer-web' );
const Vuepress = require( '../mixins/vuepress' );
module.exports = {
name: 'api',
mixins: [
Vuepress,
ApiGateway
],
settings: {
port: process.env.PORT || 3000,
routes: [{
path: "/api",
whitelist: [ "**" ]
}]
}
};
Add build script to package.json
{
"scripts": {
"build": "vuepress build public"
}
}