How to use the @sanity/server.getWebpackCompiler function in @sanity/server

To help you get started, we’ve selected a few @sanity/server 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 sanity-io / sanity / packages / @sanity / core / src / actions / build / buildStaticAssets.js View on Github external
await tryInitializePluginConfigs({workDir, output, env: 'production'})

  checkStudioDependencyVersions(workDir)

  const envVars = webpackIntegration.getSanityEnvVars({env: 'production', basePath: workDir})
  const envVarKeys = Object.keys(envVars)
  if (envVarKeys.length > 0) {
    output.print(
      '\nIncluding the following environment variables as part of the JavaScript bundle:'
    )
    envVarKeys.forEach(key => output.print(`- ${key}`))
    output.print('')
  }

  const compiler = getWebpackCompiler(compilationConfig)
  const compile = promisify(compiler.run.bind(compiler))
  let shouldDelete = true

  if (outputDir !== defaultOutputDir && !unattendedMode) {
    shouldDelete = await prompt.single({
      type: 'confirm',
      message: `Do you want to delete the existing directory (${outputDir}) first?`,
      default: true
    })
  }

  let spin

  if (shouldDelete) {
    const deleteStart = Date.now()
    spin = output.spinner('Clearing output folder').start()
github sanity-io / sanity / packages / @sanity / cli / src / commands / build / buildCommand.js View on Github external
handler: ({output, options}) => {
    const outputDir = options._[1] || path.join(options.rootDir, 'dist')
    const config = getConfig(options.rootDir).get('server')
    const compilationConfig = {
      env: 'production',
      staticPath: resolveStaticPath(options.rootDir, config),
      basePath: options.rootDir,
      outputPath: path.join(outputDir, 'static')
    }

    const compiler = getWebpackCompiler(compilationConfig)
    const compile = thenify(compiler.run.bind(compiler))

    const spin = output.spinner('Building Sanity...')
    spin.start()

    const bundle = {}

    return compile()
      .then(statistics => {
        const stats = statistics.toJson()
        if (stats.errors && stats.errors.length > 0) {
          throw new Error(
            `Errors while building:\n\n${stats.errors.join('\n\n')}`
          )
        }