gpt4 book ai didi

asp.net - Gulp VS2015 .Net5

转载 作者:行者123 更新时间:2023-12-02 14:39:49 27 4
gpt4 key购买 nike

我正在尝试学习 Gulp,但无法通过任务运行资源管理器成功运行任务。没有任务出现,资源管理器显示错误:无法加载,请参阅输出窗口以获取更多信息。检查输出窗口时,似乎找不到我的project.json。

Failed to run "F:\Projects\NewInventory\src\NewInventory\Gulpfile.js"...
cmd.exe /c gulp --tasks-simple
Error: Cannot find module ' ./project.json'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (F:\Projects\NewInventory\src\NewInventory\gulpfile.js:12:15)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)

Failed to run "F:\Projects\NewInventory\src\NewInventory\Gulpfile.js"...
cmd.exe /c gulp --tasks-simple
Error: Cannot find module ' ./project.json'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (F:\Projects\NewInventory\src\NewInventory\gulpfile.js:12:15)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)

但是,我还从头开始创建了一个新的 .Net5 Web 应用程序,并与我当前的项目进行比较,以确保 project.json 位于正确的目录位置。

我的project.json如下:

 "webroot": "wwwroot",
"userSecretsId": "aspnet5-NewInventory-f5a8bab7-e95b-485b-97e9-9a072438b107",
"version": "1.0.0-*",

"dependencies": {
"EntityFramework.SqlServer": "7.0.0-beta8",
"EntityFramework.Commands": "7.0.0-beta8",
"Microsoft.AspNet.Mvc": "6.0.0-beta8",
"Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-beta8",
"Microsoft.AspNet.Http.Features": "1.0.0-beta8",
"Microsoft.AspNet.Http.Abstractions": "1.0.0-beta8",
"Microsoft.AspNet.Authentication.Cookies": "1.0.0-beta8",
"Microsoft.AspNet.Authentication.Facebook": "1.0.0-beta8",
"Microsoft.AspNet.Authentication.Google": "1.0.0-beta8",
"Microsoft.AspNet.Authentication.MicrosoftAccount": "1.0.0-beta8",
"Microsoft.AspNet.Authentication.Twitter": "1.0.0-beta8",
"Microsoft.AspNet.Diagnostics": "1.0.0-beta8",
"Microsoft.AspNet.Diagnostics.Entity": "7.0.0-beta8",
"Microsoft.AspNet.Identity.EntityFramework": "3.0.0-beta8",
"Microsoft.AspNet.IISPlatformHandler": "1.0.0-beta8",
"Microsoft.AspNet.Server.Kestrel": "1.0.0-beta8",
"Microsoft.AspNet.StaticFiles": "1.0.0-beta8",
"Microsoft.AspNet.Tooling.Razor": "1.0.0-beta8",
"Microsoft.Framework.Configuration": "1.0.0-beta8",
"Microsoft.Framework.Configuration.Abstractions": "1.0.0-beta8",
"Microsoft.Framework.Configuration.Binder": "1.0.0-beta8",
"Microsoft.Framework.Configuration.Json": "1.0.0-beta8",
"Microsoft.Framework.Configuration.UserSecrets": "1.0.0-beta8",
"Microsoft.Framework.Logging": "1.0.0-beta8",
"Microsoft.Framework.Logging.Console": "1.0.0-beta8",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-beta8",
"Microsoft.Framework.Logging.Debug": "1.0.0-beta8"
},

"commands": {
"web": "Microsoft.AspNet.Server.Kestrel",
"ef": "EntityFramework.Commands"
},

"frameworks": {
"dnx451": { },
"dnxcore50": { }
},

"exclude": [
"wwwroot",
"node_modules",
"bower_components"
],
"publishExclude": [
"node_modules",
"bower_components",
"**.xproj",
"**.user",
"**.vspscc"
],
"scripts": {
"prepublish": [ "npm install", "bower install", "gulp clean", "gulp min" ]
},
"configurations": {
}
}

包.json

{
"name": "ASP.NET",
"version": "0.0.0",
"devDependencies": {
"gulp": "3.8.11",
"gulp-concat": "2.5.2",
"gulp-cssmin": "0.1.7",
"gulp-uglify": "1.2.0",
"gulp-jshint": "1.11.2",
"rimraf": "2.2.8",
"del": "2.0.2",
"gulp-bower": "0.0.10",
"npm-check-updates": "2.3.2"
}
}

Gulpfile.js

var gulp = require("gulp"),
rimraf = require("rimraf"),
concat = require("gulp-concat"),
cssmin = require("gulp-cssmin"),
uglify = require("gulp-uglify"),
project = require("./project.json");

var bower = require('gulp-bower');
var del = require('del');
var project = require(' ./project.json');
var lib = project.webroot + '/lib';

var paths = {
webroot: "./" + project.webroot + "/"
};

paths.js = paths.webroot + "js/**/*.js";
paths.minJs = paths.webroot + "js/**/*.min.js";
paths.css = paths.webroot + "css/**/*.css";
paths.minCss = paths.webroot + "css/**/*.min.css";
paths.concatJsDest = paths.webroot + "js/site.min.js";
paths.concatCssDest = paths.webroot + "css/site.min.css";

gulp.task('default', ['bower:install'], function () {
return;
});

gulp.task('bower:install', ['clean'], function () {
return bower({
directory: lib
});
});

gulp.task('clean', function (done) {
del(lib, done);
});

gulp.task("clean:js", function (cb) {
rimraf(paths.concatJsDest, cb);
});

gulp.task("clean:css", function (cb) {
rimraf(paths.concatCssDest, cb);
});

gulp.task("clean", ["clean:js", "clean:css"]);

gulp.task("min:js", function () {
gulp.src([paths.js, "!" + paths.minJs], { base: "." })
.pipe(concat(paths.concatJsDest))
.pipe(uglify())
.pipe(gulp.dest("."));
});

gulp.task("min:css", function () {
gulp.src([paths.css, "!" + paths.minCss])
.pipe(concat(paths.concatCssDest))
.pipe(cssmin())
.pipe(gulp.dest("."));
});

gulp.task("min", ["min:js", "min:css"]);

最佳答案

您可以通过删除该行来修复错误

var project = require(' ./project.json');

路径文字开头的空格表示它不指向project.json。在执行您需要执行的操作之前有一行;

var gulp = require("gulp"),
rimraf = require("rimraf"),
concat = require("gulp-concat"),
cssmin = require("gulp-cssmin"),
uglify = require("gulp-uglify"),
project = require("./project.json"); <---- This is doing what you expected.

关于asp.net - Gulp VS2015 .Net5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33196250/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com