找不到临时文件的带有单数glob的文件



我是Gulp系统的新手,我正在尝试启动并运行我的AngularJS应用程序。使用Yeoman,我得到了一组标准的吞咽任务,但其中一个任务失败了,并显示了错误消息。我已经把它缩小到了一行,但我对这个系统的了解还不够,不知道是什么失败了或为什么失败(当然,除了丢失文件的名称)。

失败的gulp文件如下:

const gulp = require('gulp');
const filter = require('gulp-filter');
const useref = require('gulp-useref');
const lazypipe = require('lazypipe');
const rev = require('gulp-rev');
const revReplace = require('gulp-rev-replace');
const uglify = require('gulp-uglify');
const cssnano = require('gulp-cssnano');
const htmlmin = require('gulp-htmlmin');
const sourcemaps = require('gulp-sourcemaps');
const uglifySaveLicense = require('uglify-save-license');
const ngAnnotate = require('gulp-ng-annotate');
const conf = require('../conf/gulp.conf');
gulp.task('build', build);
function build() {
const htmlFilter = filter(conf.path.tmp('*.html'), {restore: true});
const jsFilter = filter(conf.path.tmp('**/*.js'), {restore: true});
const cssFilter = filter(conf.path.tmp('**/*.css'), {restore: true});
return gulp.src(conf.path.tmp('/index.html'))
.pipe(useref({}, lazypipe().pipe(sourcemaps.init, {loadMaps: true})))
// .pipe(jsFilter)
// .pipe(ngAnnotate())
// .pipe(uglify({preserveComments: uglifySaveLicense})).on('error', conf.errorHandler('Uglify'))
// .pipe(rev())
// .pipe(jsFilter.restore)
// .pipe(cssFilter)
// .pipe(cssnano())
// .pipe(rev())
// .pipe(cssFilter.restore)
// .pipe(revReplace())
// .pipe(sourcemaps.write('maps'))
// .pipe(htmlFilter)
// .pipe(htmlmin())
// .pipe(htmlFilter.restore)
// .pipe(gulp.dest(conf.path.dist()));
}

正如你所看到的,除了那句冒犯性的话,我已经把所有的评论都删掉了。当作为构建过程的一部分调用该行时,会产生以下错误消息:

[17:22:27] 'build' errored after 42 ms
[17:22:27] Error: Error: File not found with singular glob: C:UsersJeffrey GetzinDocumentsGitHubVisualStudionewclient.tmpjspm_packagessystem.js
at DestroyableTransform.<anonymous> (C:UsersJeffrey GetzinDocumentsGitHubVisualStudionewclientnode_modulesgulp-userefindex.js:65:28)
at emitOne (events.js:101:20)
at DestroyableTransform.emit (events.js:188:7)
at emitOne (events.js:101:20)
at Through2.emit (events.js:188:7)
at OrderedStreams.<anonymous> (C:UsersJeffrey GetzinDocumentsGitHubVisualStudionewclientnode_modulesglob-streamindex.js:140:20)
at emitOne (events.js:96:13)
at OrderedStreams.emit (events.js:188:7)
at emitOne (events.js:96:13)
at DestroyableTransform.emit (events.js:188:7)
at Glob.<anonymous> (C:UsersJeffrey GetzinDocumentsGitHubVisualStudionewclientnode_modulesglob-streamindex.js:40:16)
at Glob.g (events.js:286:16)
at emitOne (events.js:96:13)
at Glob.emit (events.js:188:7)
at Glob._finish (C:UsersJeffrey GetzinDocumentsGitHubVisualStudionewclientnode_modulesglob-streamnode_modulesglobglob.js:172:8)
at done (C:UsersJeffrey GetzinDocumentsGitHubVisualStudionewclientnode_modulesglob-streamnode_modulesglobglob.js:159:12)
[17:22:27] 'build' errored after 25 s
[17:22:27] 'default' errored after 25 s
[17:22:27] 'serve:dist' errored after 25 s
Process finished with exit code 1

显然,它在jspm包的临时副本中寻找system.js,但为什么为什么它找不到它?文件应该在那里吗?我不知道gullow脚本想做什么,所以我不能冒险猜测为什么它不起作用。

我知道这可能不足以提供全面的答案,但我希望这里有足够的信息让你至少为我指明正确的方向。

谢谢!

2017年1月3日更新

我有点搞清楚了useref应该做什么。我的index.html文件是

<!doctype html>
<html>
<head>
<base href="/">
<meta charset="utf-8">
<title>FountainJS</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" type="image/png" href="http://fountainjs.io/assets/imgs/fountain.png" />
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="css/camera.css" type="text/css" media="screen">
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen">
<!-- build:css(.tmp) index.css -->
<link rel="stylesheet" href="index.css"></link>
<!-- endbuild -->
</head>
<body class="front" ng-app="app">
<div id="main">
<ui-view></ui-view>
<page-footer></page-footer>
</div>
</body>
<!-- build:js(.tmp) index.js -->
<script src="jspm_packages/system.js"></script>
<script src="jspm.browser.js"></script>
<script src="jspm.config.js"></script>
<script>
System.import('src/index.ts');
</script>
<!-- endbuild -->
</html>

我认为应该发生的是,它应该取代块:

<!-- build:js(.tmp) index.js -->
<script src="jspm_packages/system.js"></script>
<script src="jspm.browser.js"></script>
<script src="jspm.config.js"></script>
<script>
System.import('src/index.ts');
</script>
<!-- endbuild -->

带有

<script src="tmp/index.js"></script>

这听起来正确吗?

我实际上已经找到了解决方案,但它并不明显。我了解到,Gulp的一个问题是,通过将所有东西分解成专有的小块,很难看到全局。这意味着我需要做一些深潜水来发现问题所在。

出现错误的是之前到useref阶段。它发生在管道执行<index.html>.pipe(replace(<pattern-describing-the-existing-javascript-includes>, '<script src="index.js">')时。

我记不起约曼种子项目中的确切正则表达式,但它对如何终止行存在偏见。正则表达式大致如下:

/line1stuffnline2stuff/

我花了很多调试才追踪到这一点,但我注意到regex在regexpal中工作,但当我进行实际替换时,没有替换任何内容。

凭直觉,我尝试将正则表达式更改为:

/line1stuff[nr]+line2stuff/

这就解决了问题!(或者至少这个特定的问题;我遇到了后续的问题。)

伙计,这些东西一点都不明显。基本上,我不得不用console.infoconsole.warnconsole.error调用来遍历所有的gullow脚本,以找到有问题的代码段。

无论如何,我希望这个答案能在其他人陷入同样疯狂的问题时有所帮助!:)

最新更新