从azure dev ops管道构建gatsbyjs网站

时间:2019-01-04 21:33:56

标签: gulp azure-devops gatsby

我正在尝试根据Azure Dev ops构建定义构建一个gatsby静态网站。

AzureDev ops提供了一个gulp任务,因此我试图创建一个简单的gulpfile来包装gatsby的构建过程。

现在我尝试了:

const gatbsyCli = require('gatsby-cli/lib/create-cli');

function gatsbyBuild() {
    gatbsyCli([ 'build' ]);
}

exports.gatsbyBuild = gatsbyBuild;

但是,该任务仅显示命令行帮助:

Usage: gulp.js <command> [options]

Commands:
  gulp.js develop                   Start development server. Watches files, rebuilds, and hot reloads if something
                                    changes
  gulp.js build                     Build a Gatsby project.
  gulp.js serve                     Serve previously built Gatsby site.
  gulp.js info                      Get environment information for debugging and issue reporting
  gulp.js repl                      Get a node repl with context of Gatsby environment, see (add docs link here)
  gulp.js new [rootPath] [starter]  Create new Gatsby project.

Options:
  --verbose      Turn on verbose output                                                       [boolean] [default: false]
  --no-color     Turn off the color in output                                                 [boolean] [default: false]
  -h, --help     Show help                                                                                     [boolean]
  -v, --version  Show version number                                                                           [boolean]

Pass --help to see all available commands and options.
[22:28:15] The following tasks did not complete: gatsbyBuild
[22:28:15] Did you forget to signal async completion?

如何从gulp构建gatsby网站?

还有什么更好的方法可以实现我的目标?

[编辑] 也尝试过:

const gatbsyBuildImpl = require('gatsby/dist/commands/build.js');

function gatsbyBuild() {
    gatbsyBuildImpl();
}

exports.gatsbyBuild = gatsbyBuild;

但失败并显示TypeError: Cannot read property 'openTracingConfigFile' of undefined

[/编辑]

[编辑2019-02-02] 关于答案,这是有关我的进度的更新。

首先,我尝试使用NPM操作来构建网站,例如suggested

但是,它失败并显示以下错误:

2019-02-02T21:13:22.3306376Z [command]/usr/local/bin/npm run build
2019-02-02T21:13:27.6097839Z error GraphQL Error There was an error while compiling your site's GraphQL queries.
2019-02-02T21:13:27.6098171Z 
2019-02-02T21:13:27.6099612Z   Error: RelayParser: Encountered duplicate defintitions for one or more documents: each document must have a unique name. Duplicated documents:
2019-02-02T21:13:27.6100019Z > gatsby-starter-blog@1.0.0 build /home/vsts/work/1/s
2019-02-02T21:13:27.6100847Z - DefaultSEOQuery
2019-02-02T21:13:27.6100902Z > gatsby build

但是,我不明白此错误。该网站可以在本地完美构建。

我的gatbsy-node.js查询是:

            `
{
  allMarkdownRemark(sort: {fields: [frontmatter___date], order: DESC}, limit: 1000) {
    edges {
      node {
        fields {
          slug
        }
        frontmatter {
          title
        }
      }
    }
    cats: group(field: frontmatter___categories, limit:1000) {
      fieldValue
      totalCount
    }
    tags: group(field: frontmatter___tags, limit:1000) {
      fieldValue
      totalCount
    }
  }
}

此外,这是我的Yaml定义:

resources:  
- repo: self    
queue:    
  name: Hosted Ubuntu 1604    
  demands: npm

steps:    
- task: Npm@1    
  displayName: 'npm install'    
  inputs:    
    verbose: false       

- task: Npm@1    
  displayName: 'npm custom'    
  inputs:    
    command: custom        
    verbose: false  
    customCommand: 'run build'

移至“托管”代理,引发另一个错误:

019-02-02T21:52:17.2419822Z [0m
2019-02-02T21:52:17.2419867Z [0m  [0m[97m[41mError[0m[37m[41m:[0m[37m[41m [0m[97m[41m0-0cf4e58448448331aa6c.js from Terser[0m
2019-02-02T21:52:17.2421623Z [0m  [0m[97m[41mTypeError: Cannot read property 'minify' of undefined[0m
2019-02-02T21:52:17.2421678Z [0m  [0m[97m[41m    at minify (D:\a\1\s\node_modules\terser-webpack-plugin\dist\minify.js:175:[0m  [0m[97m[41m22)[0m
2019-02-02T21:52:17.2421746Z [0m  [0m[97m[41m    at TaskRunner.boundWorkers.error [as boundWorkers] (D:\a\1\s\node_modules\[0m  [0m[97m[41mterser-webpack-plugin\dist\TaskRunner.js:68:40)[0m
2019-02-02T21:52:17.2421794Z [0m  [0m[97m[41m    at enqueue (D:\a\1\s\node_modules\terser-webpack-plugin\dist\TaskRunner.js[0m  [0m[97m[41m:89:14)[0m
2019-02-02T21:52:17.2421841Z [0m  [0m[97m[41m    at tryCatcher (D:\a\1\s\node_modules\bluebird\js\release\util.js:16:23)[0m
2019-02-02T21:52:17.2421906Z [0m  [0m[97m[41m    at Promise._settlePromiseFromHandler (D:\a\1\s\node_modules\bluebird\js\re[0m  [0m[97m[41mlease\promise.js:512:31)[0m
2019-02-02T21:52:17.2421954Z [0m  [0m[97m[41m    at Promise._settlePromise (D:\a\1\s\node_modules\bluebird\js\release\promi[0m  [0m[97m[41mse.js:569:18)[0m
2019-02-02T21:52:17.2422390Z [0m  [0m[97m[41m    at Promise._settlePromise0 (D:\a\1\s\node_modules\bluebird\js\release\prom[0m  [0m[97m[41mise.js:614:10)[0m
2019-02-02T21:52:17.2422463Z [0m  [0m[97m[41m    at Promise._settlePromises (D:\a\1\s\node_modules\bluebird\js\release\prom[0m  [0m[97m[41mise.js:690:18)[0m
2019-02-02T21:52:17.2422512Z [0m  [0m[97m[41m    at _drainQueueStep (D:\a\1\s\node_modules\bluebird\js\release\async.js:138[0m  [0m[97m[41m:12)[0m
2019-02-02T21:52:17.2422560Z [0m  [0m[97m[41m    at _drainQueue (D:\a\1\s\node_modules\bluebird\js\release\async.js:131:9)[0m
2019-02-02T21:52:17.2422626Z [0m  [0m[97m[41m    at Async._drainQueues (D:\a\1\s\node_modules\bluebird\js\release\async.js:[0m  [0m[97m[41m147:5)[0m
2019-02-02T21:52:17.2422677Z [0m  [0m[97m[41m    at Immediate.Async.drainQueues (D:\a\1\s\node_modules\bluebird\js\release\[0m  [0m[97m[41masync.js:17:14)[0m
2019-02-02T21:52:17.2422769Z [0m  [0m[97m[41m    at runCallback (timers.js:637:20)[0m
2019-02-02T21:52:17.2422832Z [0m  [0m[97m[41m    at tryOnImmediate (timers.js:610:5)[0m
2019-02-02T21:52:17.2422878Z [0m  [0m[97m[41m    at processImmediate [as _immediateCallback] (timers.js:582:5)[0m

npm ERR! Failed at the gatsby-starter-blog@1.0.0 build script 'gatsby build'.
2019-02-02T21:52:17.2430701Z npm ERR! Make sure you have the latest version of node.js and npm installed.
2019-02-02T21:52:17.2430849Z npm ERR! If you do, this is most likely a problem with the gatsby-starter-blog package,
2019-02-02T21:52:17.2431116Z npm ERR! not with npm itself.

1 个答案:

答案 0 :(得分:2)

您可以简单地使用npm。两个构建步骤足以满足您的第一个要求:

  1. 安装依赖项

    sudo npm install --unsafe-perm=true

  2. 构建

    npm install

在您可以执行以下操作之前,您的 package.json 需要以下脚本(在每个可用的gatsbyJS Boilerplate中):

enter image description here