# Node.js API
# Initialization
First, you need to initialize the API for your style guide config.
Using a JavaScript object:
const styleguidist = require('vue-styleguidist')
const styleguide = styleguidist({
logger: {
warn: console.warn,
info: console.log,
debug: console.log
},
components: './lib/components/**/*.vue',
webpackConfig: {
module: {
rules: [
{
test: /\.vue$/,
exclude: /node_modules/,
loader: 'vue-loader'
},
{
test: /\.js?$/,
exclude: /node_modules/,
loader: 'babel-loader'
},
{
test: /\.css$/,
loader: 'style-loader!css-loader?modules'
}
]
}
}
})
Using a config file:
const styleguidist = require('vue-styleguidist')
const styleguide = styleguidist(require('../styleguide.config.js'))
Or auto searching a config file:
const styleguidist = require('vue-styleguidist')
const styleguide = styleguidist()
See all available config options.
Note: console output is turned off by default, you may need to define your own logger.
# Methods
# build(callback)
# Arguments
callback(err, config, stats)
(Function): A callback to be invoked when style guide is built:err
(Object): error details.config
(Object): normalized style guide config.stats
(Object): webpack build stats.
# Returns
(Compiler): webpack Compiler
instance.
# Example
const styleguidist = require('vue-styleguidist')
styleguidist(require('../styleguide.config.js')).build(
(err, config) => {
if (err) {
console.log(err)
} else {
console.log('Style guide published to', config.styleguideDir)
}
}
)
# server(callback)
# Arguments
callback(err, config)
(Function): A callback to be invoked when style guide is built:err
(Object): error details.config
(Object): normalized style guide config.
# Returns
(Object): Object containing a webpack Compiler
instance and the vue-styleguidist Server
# Example
const styleguidist = require('vue-styleguidist')
styleguidist(require('../styleguide.config.js')).server(
(err, config) => {
if (err) {
console.log(err)
} else {
const url = `http://${config.serverHost}:${config.serverPort}`
console.log(`Listening at ${url}`)
}
}
)
# makeWebpackConfig([env])
# Arguments
- [
env
='production'
] (String):production
ordevelopment
.
# Returns
(Object): webpack config.
# Example
// webpack.config.js
module.exports = [
{
// User webpack config
},
require('vue-styleguidist')().makeWebpackConfig()
]
← Cookbook Deployment →