【发布时间】:2017-01-02 22:35:41
【问题描述】:
我是 Gulp 系统的新手,我正在尝试启动并运行我的 AngularJS 应用程序。使用 Yeoman,我得到了一组标准的 gulp 任务,但其中一个任务失败并显示错误消息。我已将其缩小到特定的行,但我对这个系统的了解不够多,无法知道失败的原因或原因(当然,除了丢失文件的名称)。
失败的 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:\Users\Jeffrey Getzin\Documents\GitHubVisualStudio\newclient\.tmp\jspm_packages\system.js
at DestroyableTransform.<anonymous> (C:\Users\Jeffrey Getzin\Documents\GitHubVisualStudio\newclient\node_modules\gulp-useref\index.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:\Users\Jeffrey Getzin\Documents\GitHubVisualStudio\newclient\node_modules\glob-stream\index.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:\Users\Jeffrey Getzin\Documents\GitHubVisualStudio\newclient\node_modules\glob-stream\index.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:\Users\Jeffrey Getzin\Documents\GitHubVisualStudio\newclient\node_modules\glob-stream\node_modules\glob\glob.js:172:8)
at done (C:\Users\Jeffrey Getzin\Documents\GitHubVisualStudio\newclient\node_modules\glob-stream\node_modules\glob\glob.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,但是为什么? 为什么找不到呢?文件应该在那里吗?我不知道 gulp 脚本试图做什么,所以我无法猜测它为什么不起作用。
我知道这可能不足以提供全面的答案,但我希望这里有足够的信息让您至少为我指明正确的方向。
谢谢!
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>
这听起来正确吗?
【问题讨论】:
-
你的 conf.path.tmp 函数是什么样子的?
标签: angularjs gulp jspm gulp-sourcemaps