How to use @vuepress/shared-utils - 10 common examples

To help you get started, we’ve selected a few @vuepress/shared-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vuejs / vuepress / packages / @vuepress / core / lib / build.js View on Github external
const createServerConfig = require('./webpack/createServerConfig')
  const { createBundleRenderer } = require('vue-server-renderer')
  const { normalizeHeadTag, applyUserWebpackConfig } = require('./util/index')

  logger.wait('\nExtracting site metadata...')
  const options = await prepare(sourceDir, cliOptions, true /* isProd */)
  if (cliOptions.outDir) {
    options.outDir = cliOptions.outDir
  }

  const { outDir } = options
  if (process.cwd() === outDir) {
    return console.error(logger.error(chalk.red('Unexpected option: outDir cannot be set to the current working directory.\n'), false))
  }
  await fs.remove(outDir)
  logger.debug('Dist directory: ' + chalk.gray(require('path').resolve(process.cwd(), outDir)))

  let clientConfig = createClientConfig(options, cliOptions).toConfig()
  let serverConfig = createServerConfig(options, cliOptions).toConfig()

  // apply user config...
  const userConfig = options.siteConfig.configureWebpack
  if (userConfig) {
    clientConfig = applyUserWebpackConfig(userConfig, clientConfig, false)
    serverConfig = applyUserWebpackConfig(userConfig, serverConfig, true)
  }

  // compile!
  const stats = await compile([clientConfig, serverConfig])

  const serverBundle = require(path.resolve(outDir, 'manifest/server.json'))
  const clientManifest = require(path.resolve(outDir, 'manifest/client.json'))
github vuejs / vuepress / packages / @vuepress / core / lib / build.js View on Github external
module.exports = async function build (sourceDir, cliOptions = {}) {
  process.env.NODE_ENV = 'production'

  const { path } = require('@vuepress/shared-utils')
  const webpack = require('webpack')
  const readline = require('readline')
  const escape = require('escape-html')

  const { chalk, fs, logger } = require('@vuepress/shared-utils')
  const prepare = require('./prepare/index')
  const createClientConfig = require('./webpack/createClientConfig')
  const createServerConfig = require('./webpack/createServerConfig')
  const { createBundleRenderer } = require('vue-server-renderer')
  const { normalizeHeadTag, applyUserWebpackConfig } = require('./util/index')

  logger.wait('\nExtracting site metadata...')
  const options = await prepare(sourceDir, cliOptions, true /* isProd */)
  if (cliOptions.outDir) {
    options.outDir = cliOptions.outDir
  }

  const { outDir } = options
  if (process.cwd() === outDir) {
    return console.error(logger.error(chalk.red('Unexpected option: outDir cannot be set to the current working directory.\n'), false))
  }
  await fs.remove(outDir)
  logger.debug('Dist directory: ' + chalk.gray(require('path').resolve(process.cwd(), outDir)))

  let clientConfig = createClientConfig(options, cliOptions).toConfig()
  let serverConfig = createServerConfig(options, cliOptions).toConfig()

  // apply user config...
github vuejs / vuepress / packages / @vuepress / core / lib / build.js View on Github external
module.exports = async function build (sourceDir, cliOptions = {}) {
  process.env.NODE_ENV = 'production'

  const webpack = require('webpack')
  const readline = require('readline')
  const escape = require('escape-html')

  const { chalk, fs, path, logger, env, performance } = require('@vuepress/shared-utils')
  const prepare = require('./prepare/index')
  const createClientConfig = require('./webpack/createClientConfig')
  const createServerConfig = require('./webpack/createServerConfig')
  const { createBundleRenderer } = require('vue-server-renderer')
  const { normalizeHeadTag, applyUserWebpackConfig } = require('./util/index')

  logger.wait('Extracting site metadata...')
  const ctx = await prepare(sourceDir, cliOptions, true /* isProd */)

  const { outDir, cwd } = ctx
  if (cwd === outDir) {
    return console.error(logger.error(chalk.red('Unexpected option: outDir cannot be set to the current working directory.\n'), false))
  }

  await fs.emptyDir(outDir)
  logger.debug('Dist directory: ' + chalk.gray(outDir))

  let clientConfig = createClientConfig(ctx, cliOptions).toConfig()
  let serverConfig = createServerConfig(ctx, cliOptions).toConfig()

  // apply user config...
  const userConfig = ctx.siteConfig.configureWebpack
  if (userConfig) {
github vuejs / vuepress / packages / @vuepress / core / lib / build.js View on Github external
const readline = require('readline')
  const escape = require('escape-html')

  const { chalk, fs, path, logger, env, performance } = require('@vuepress/shared-utils')
  const prepare = require('./prepare/index')
  const createClientConfig = require('./webpack/createClientConfig')
  const createServerConfig = require('./webpack/createServerConfig')
  const { createBundleRenderer } = require('vue-server-renderer')
  const { normalizeHeadTag, applyUserWebpackConfig } = require('./util/index')

  logger.wait('Extracting site metadata...')
  const ctx = await prepare(sourceDir, cliOptions, true /* isProd */)

  const { outDir, cwd } = ctx
  if (cwd === outDir) {
    return console.error(logger.error(chalk.red('Unexpected option: outDir cannot be set to the current working directory.\n'), false))
  }

  await fs.emptyDir(outDir)
  logger.debug('Dist directory: ' + chalk.gray(outDir))

  let clientConfig = createClientConfig(ctx, cliOptions).toConfig()
  let serverConfig = createServerConfig(ctx, cliOptions).toConfig()

  // apply user config...
  const userConfig = ctx.siteConfig.configureWebpack
  if (userConfig) {
    clientConfig = applyUserWebpackConfig(userConfig, clientConfig, false)
    serverConfig = applyUserWebpackConfig(userConfig, serverConfig, true)
  }

  // compile!
github vuejs / vuepress / packages / @vuepress / core / lib / build.js View on Github external
const { chalk, fs, logger } = require('@vuepress/shared-utils')
  const prepare = require('./prepare/index')
  const createClientConfig = require('./webpack/createClientConfig')
  const createServerConfig = require('./webpack/createServerConfig')
  const { createBundleRenderer } = require('vue-server-renderer')
  const { normalizeHeadTag, applyUserWebpackConfig } = require('./util/index')

  logger.wait('\nExtracting site metadata...')
  const options = await prepare(sourceDir, cliOptions, true /* isProd */)
  if (cliOptions.outDir) {
    options.outDir = cliOptions.outDir
  }

  const { outDir } = options
  if (process.cwd() === outDir) {
    return console.error(logger.error(chalk.red('Unexpected option: outDir cannot be set to the current working directory.\n'), false))
  }
  await fs.remove(outDir)
  logger.debug('Dist directory: ' + chalk.gray(require('path').resolve(process.cwd(), outDir)))

  let clientConfig = createClientConfig(options, cliOptions).toConfig()
  let serverConfig = createServerConfig(options, cliOptions).toConfig()

  // apply user config...
  const userConfig = options.siteConfig.configureWebpack
  if (userConfig) {
    clientConfig = applyUserWebpackConfig(userConfig, clientConfig, false)
    serverConfig = applyUserWebpackConfig(userConfig, serverConfig, true)
  }

  // compile!
  const stats = await compile([clientConfig, serverConfig])
github vuejs / vuepress / packages / @vuepress / core / lib / build.js View on Github external
// render pages
  logger.wait('Rendering static HTML...')

  const pagePaths = []
  for (const page of ctx.pages) {
    pagePaths.push(await renderPage(page))
  }

  readline.clearLine(process.stdout, 0)
  readline.cursorTo(process.stdout, 0)

  await ctx.pluginAPI.options.generated.apply(pagePaths)

  // DONE.
  const relativeDir = path.relative(cwd, outDir)
  logger.success(`Generated static files in ${chalk.cyan(relativeDir)}.`)
  const { duration } = performance.stop()
  logger.developer(`It took a total of ${chalk.cyan(`${duration}ms`)} to run the ${chalk.cyan('vuepress build')}.`)
  console.log()

  // --- helpers ---

  function compile (config) {
    return new Promise((resolve, reject) => {
      webpack(config, (err, stats) => {
        if (err) {
          return reject(err)
        }
        if (stats.hasErrors()) {
          stats.toJson().errors.forEach(err => {
            console.error(err)
github vuejs / vuepress / packages / @vuepress / core / lib / node / build / index.js View on Github external
// render pages
    logger.wait('Rendering static HTML...')

    const pagePaths = []
    for (const page of this.context.pages) {
      pagePaths.push(await this.renderPage(page))
    }

    readline.clearLine(process.stdout, 0)
    readline.cursorTo(process.stdout, 0)

    await this.context.pluginAPI.applyAsyncOption('generated', pagePaths)

    // DONE.
    const relativeDir = path.relative(this.context.cwd, this.outDir)
    logger.success(`Generated static files in ${chalk.cyan(relativeDir)}.`)
    const { duration } = performance.stop()
    logger.developer(`It took a total of ${chalk.cyan(`${duration}ms`)} to run the ${chalk.cyan('vuepress build')}.`)
    console.log()
  }
github vuejs / vuepress / packages / @vuepress / core / lib / node / build / index.js View on Github external
// render pages
    logger.wait('Rendering static HTML...')

    const pagePaths = []
    for (const page of this.context.pages) {
      pagePaths.push(await this.renderPage(page))
    }

    readline.clearLine(process.stdout, 0)
    readline.cursorTo(process.stdout, 0)

    await this.context.pluginAPI.applyAsyncOption('generated', pagePaths)

    // DONE.
    const relativeDir = path.relative(this.context.cwd, this.outDir)
    logger.success(`Generated static files in ${chalk.cyan(relativeDir)}.`)
    const { duration } = performance.stop()
    logger.developer(`It took a total of ${chalk.cyan(`${duration}ms`)} to run the ${chalk.cyan('vuepress build')}.`)
    console.log()
  }
github vuejs / vuepress / packages / @vuepress / core / lib / build.js View on Github external
// render pages
  logger.wait('Rendering static HTML...')

  const pagePaths = []
  for (const page of ctx.pages) {
    pagePaths.push(await renderPage(page))
  }

  readline.clearLine(process.stdout, 0)
  readline.cursorTo(process.stdout, 0)

  await ctx.pluginAPI.options.generated.apply(pagePaths)

  // DONE.
  const relativeDir = path.relative(cwd, outDir)
  logger.success(`Generated static files in ${chalk.cyan(relativeDir)}.`)
  const { duration } = performance.stop()
  logger.developer(`It took a total of ${chalk.cyan(`${duration}ms`)} to run the ${chalk.cyan('vuepress build')}.`)
  console.log()

  // --- helpers ---

  function compile (config) {
    return new Promise((resolve, reject) => {
      webpack(config, (err, stats) => {
        if (err) {
          return reject(err)
        }
        if (stats.hasErrors()) {
          stats.toJson().errors.forEach(err => {
            console.error(err)
          })
github vuejs / vuepress / packages / @vuepress / core / lib / build.js View on Github external
const createClientConfig = require('./webpack/createClientConfig')
  const createServerConfig = require('./webpack/createServerConfig')
  const { createBundleRenderer } = require('vue-server-renderer')
  const { normalizeHeadTag, applyUserWebpackConfig } = require('./util/index')

  logger.wait('\nExtracting site metadata...')
  const options = await prepare(sourceDir, cliOptions, true /* isProd */)
  if (cliOptions.outDir) {
    options.outDir = cliOptions.outDir
  }

  const { outDir } = options
  if (process.cwd() === outDir) {
    return console.error(logger.error(chalk.red('Unexpected option: outDir cannot be set to the current working directory.\n'), false))
  }
  await fs.remove(outDir)
  logger.debug('Dist directory: ' + chalk.gray(require('path').resolve(process.cwd(), outDir)))

  let clientConfig = createClientConfig(options, cliOptions).toConfig()
  let serverConfig = createServerConfig(options, cliOptions).toConfig()

  // apply user config...
  const userConfig = options.siteConfig.configureWebpack
  if (userConfig) {
    clientConfig = applyUserWebpackConfig(userConfig, clientConfig, false)
    serverConfig = applyUserWebpackConfig(userConfig, serverConfig, true)
  }

  // compile!
  const stats = await compile([clientConfig, serverConfig])

  const serverBundle = require(path.resolve(outDir, 'manifest/server.json'))