Polymer 首次运行analyzer时聚合物构建失败

Polymer 首次运行analyzer时聚合物构建失败,polymer,nunjucks,Polymer,Nunjucks,生成任务失败,之后使polymer生成在project.sources()上运行。 我正在使用预渲染模板,这就是analyzer失败的原因 Polymer({ is: 'my-app', properties: { page: { type: String, reflectToAttribute: true }, pages: { type: Array,

生成任务失败,之后使polymer生成在
project.sources()
上运行。 我正在使用预渲染模板,这就是analyzer失败的原因

Polymer({
    is: 'my-app',
    properties: {
        page: {
            type: String,
            reflectToAttribute: true
        },
        pages: {
            type: Array,
            value: {$ pages | dump | safe $}  // fails here
        }
    }
});
我的眼睛看起来像:

return project.sources()
.pipe(gulpif('**/*.{html,js,json}', template.compile(Object.assign({}, metadata, resources))))
.pipe(project.splitHtml())
...
我可以禁用或推迟(首选)analyzer吗


我的存储库:

聚合物分析器支持标准JavaScript。如果您正在使用其他语法编写,则需要在语法到达分析器之前转换该语法。聚合物构建库就是为这个用例设计的。您可以构建一个Gulp管道,在文件到达分析器之前,执行自定义转换

请参见此处的聚合物构建库:


希望有帮助

聚合物分析仪支持标准JavaScript。如果您正在使用其他语法编写,则需要在语法到达分析器之前转换该语法。聚合物构建库就是为这个用例设计的。您可以构建一个Gulp管道,在文件到达分析器之前,执行自定义转换

请参见此处的聚合物构建库:


希望有帮助

为了补充贾斯汀的答案,这里有一个例子可以说明这可能是什么样子:

return gulp.src('src/')
    .pipe(splitHTML())
    .pipe(gulpif('**/*.{html,js,json}', template.compile(Object.assign({}, metadata, resources))))
    .pipe(rejoinHTML())
    .dest('lib/');    

// once that is complete...
return project.sources()
    // .pipe(... the rest of your build pipeline!

您只需要确保polymer.json指向源代码的
lib/
目录,而不是
src/
,因为分析器需要从未插入的
lib/
目录中读取数据。

要添加到Justin的答案中,下面是一个示例:

return gulp.src('src/')
    .pipe(splitHTML())
    .pipe(gulpif('**/*.{html,js,json}', template.compile(Object.assign({}, metadata, resources))))
    .pipe(rejoinHTML())
    .dest('lib/');    

// once that is complete...
return project.sources()
    // .pipe(... the rest of your build pipeline!

您只需要确保polymer.json指向源代码的
lib/
目录,而不是
src/
,因为分析器需要从未插入的
lib/
目录中读取数据。

我找到了解决方案。看起来并不完美,但很有效。构建分为3个步骤:

基于PolymerJson使用nunjuck编译到
.temp
目录

return gulp.src([
...polymerJson.sources,
polymerJson.entrypoint 
], {base: '.'})
.pipe(gulpif(/\.(html|js|json)$/, nunjucks.compile(metadata, {
  tags: {
    variableStart: '{$',
    variableEnd: '$}'
  }
})))
.pipe(gulpif(/\.(html|js)$/, replace('bower_components', '../bower_components')))
.pipe(gulp.dest(config.tempDirectory));
优化和建设项目

let polymerProject = null;
console.log(`Deleting ${config.build.rootDirectory} and ${config.tempDirectory} directories...`);

del([config.build.rootDirectory, config.tempDirectory])
  .then(() => {
    console.log(`Compiling template...`);

    const compileStream = template.compile(config, polymerJson)
      .on('end', () => {
        polymerProject = new polymerBuild.PolymerProject(buildPolymerJson);
      });
    return waitFor(compileStream);
  })
  .then(() => {
    console.log(`Polymer building...`);

    const sourcesStream = polymerProject.sources()
      .pipe(polymerProject.splitHtml())
      // splitHtml doesn't split CSS https://github.com/Polymer/polymer-build/issues/32
      .pipe(gulpif(/\.js$/, uglify()))
      .pipe(gulpif(/\.(html|css)$/, cssSlam()))
      .pipe(gulpif(/\.html$/, html.minify()))
      .pipe(gulpif(/\.(png|gif|jpg|svg)$/, images.minify()))
      .pipe(polymerProject.rejoinHtml());
不要忘记从
build/.temp
目录中移动文件:

return gulp.src(`${config.build.rootDirectory}/${config.tempDirectory}/**/*`,
{base: `${config.build.rootDirectory}/${config.tempDirectory}`})
.pipe(gulpif(/\.(html|js)$/, replace('../bower_components', 'bower_components')))
.pipe(gulpif(/\.(html|js)$/, replace('/.temp', '')))
.pipe(gulp.dest(config.build.rootDirectory));

这是完整的

我找到了一个解决方案。看起来并不完美,但很有效。构建分为3个步骤:

基于PolymerJson使用nunjuck编译到
.temp
目录

return gulp.src([
...polymerJson.sources,
polymerJson.entrypoint 
], {base: '.'})
.pipe(gulpif(/\.(html|js|json)$/, nunjucks.compile(metadata, {
  tags: {
    variableStart: '{$',
    variableEnd: '$}'
  }
})))
.pipe(gulpif(/\.(html|js)$/, replace('bower_components', '../bower_components')))
.pipe(gulp.dest(config.tempDirectory));
优化和建设项目

let polymerProject = null;
console.log(`Deleting ${config.build.rootDirectory} and ${config.tempDirectory} directories...`);

del([config.build.rootDirectory, config.tempDirectory])
  .then(() => {
    console.log(`Compiling template...`);

    const compileStream = template.compile(config, polymerJson)
      .on('end', () => {
        polymerProject = new polymerBuild.PolymerProject(buildPolymerJson);
      });
    return waitFor(compileStream);
  })
  .then(() => {
    console.log(`Polymer building...`);

    const sourcesStream = polymerProject.sources()
      .pipe(polymerProject.splitHtml())
      // splitHtml doesn't split CSS https://github.com/Polymer/polymer-build/issues/32
      .pipe(gulpif(/\.js$/, uglify()))
      .pipe(gulpif(/\.(html|css)$/, cssSlam()))
      .pipe(gulpif(/\.html$/, html.minify()))
      .pipe(gulpif(/\.(png|gif|jpg|svg)$/, images.minify()))
      .pipe(polymerProject.rejoinHtml());
不要忘记从
build/.temp
目录中移动文件:

return gulp.src(`${config.build.rootDirectory}/${config.tempDirectory}/**/*`,
{base: `${config.build.rootDirectory}/${config.tempDirectory}`})
.pipe(gulpif(/\.(html|js)$/, replace('../bower_components', 'bower_components')))
.pipe(gulpif(/\.(html|js)$/, replace('/.temp', '')))
.pipe(gulp.dest(config.build.rootDirectory));
这里已经满了