咕噜咕噜的发球不起作用。因为注射器不见了?



在我的终端中,我收到以下错误:正在运行"注入器:sass"(注入器(任务正在验证配置中是否存在属性injector.sass。。。错误

无法处理任务。警告:缺少必需的配置属性"injector.sass"。使用--force继续。

由于警告而中止。

此外,bundles/vendor.js脚本没有加载到我的MEAN应用程序中。

我的咕哝文件是:

/* global module, require, process */
(function(){
'use strict';
module.exports = function(grunt) {
var localConfig;
try {
localConfig = require('./server/configuration/local_env.express');
} catch (e) {
localConfig = {};
}
require('jit-grunt')(grunt, {
express: 'grunt-express-server',
ngtemplates: 'grunt-angular-templates',
buildcontrol: 'grunt-build-control'
});
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-browserify');
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-injector');
grunt.loadNpmTasks('grunt-angular-templates');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-build-control');
grunt.loadNpmTasks('grunt-ng-annotate');

grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
application: {
name: 'UPBIS B2B Social Platform',
client: require('./bower.json').appPath || 'client',
js: 'client/app/**/*.js',
dist: 'dist'
},
express: {
options: {
port: process.env.PORT || 9000
},
dev: {
options: {
script: 'server/app.js',
debug: true
}
},
prod: {
options: {
script: 'dist/server/app.js'
}
}
},
open: {
server: {
url: 'http://localhost:<%= express.options.port %>'
}
},
qunit: {
all: {
options: {
urls: ['http://localhost:9002/test.html']
}
}
},
connect: {
server: {
options: {
port: 9002,
base: './client'
}
}
},
uglify: {
options: {
banner: '/*! <%= application.name %> <%= grunt.template.today("dd-mm-yyyy") %> */n',
mangle: false
},
dist: {
files: {
'dist/public/bundles/vendor.js': ['dist/public/bundles/vendor.js'],
'dist/public/bundles/code.js': ['dist/public/bundles/code.js']
}
}
},
browserify: {
dist: {
files: {
'dist/public/bundles/vendor.js': ['client/app/vendor.browserify.js'],
'dist/public/bundles/code.js': ['client/app/code.browserify.js', '<%= ngtemplates.app.dest %>']
},
}
},
jshint: {
options: {
globals: {
jQuery: true,
console: true,
module: true,
document: true
},
jshintrc: '<%= application.client %>/.jshintrc',
reporter: require('jshint-stylish')
},
server: {
options: {
jshintrc: 'server/.jshintrc'
},
src: [
'server/**/*.js',
'!server/**/*.spec.js'
]
},
serverTest: {
options: {
jshintrc: 'server/.jshintrc-spec'
},
src: ['server/**/*.spec.js']
},
all: [
'<%= application.client %>/{app,components}/**/*.js',
'!<%= application.client %>/{app,components}/**/*.spec.js',
'!<%= application.client %>/{app,components}/**/*.mock.js'
],
test: {
src: [
'<%= application.client %>/{app,components}/**/*.spec.js',
'<%= application.client %>/{app,components}/**/*.mock.js'
]
}
},
sass: { // Task
dist: { // Target
options: { // Target options
style: 'compressed',
compass: true
},
files: { // Dictionary of files
'dist/public/style.min.css': '<%= application.client %>/app/sass/style.scss' // 'destination': 'source'
}
}
},
watch: {
jshint: {
files: ['<%= application.js %>'],
tasks: ['jshint']
},
browserify: {
files: ['<%= application.js %>'],
tasks: ['browserify']
},
inject_css: {
files: ['dist/style.css'],
tasks: ['injector:css']
},
inject_bundles: {
files: ['dist/public/bundles/vendor.js', 'dist/public/bundles/code.js'],
tasks: ['injector:scripts']
},
},
ngtemplates: {
options: {
module: 'upbisApp',
htmlmin: {
collapseBooleanAttributes: true,
collapseWhitespace: true,
removeAttributeQuotes: true,
removeEmptyAttributes: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true
},
},
app: {
cwd: '<%= application.client %>',
src: ['app/**/*.html'],
dest: '.tmp/templates.js'
},
},
copy: {
dist: {
files: [{
expand: true,
dot: true,
cwd: '<%= application.client %>',
dest: '<%= application.dist %>/public',
src: [
'*.{ico,png,txt}',
'.htaccess',
'assets/**/*',
'nginx/**/*',
'index.html'
]
}, {
expand: true,
cwd: '.tmp/images',
dest: '<%= application.dist %>/public/assets/images',
src: ['generated/*']
},

{
expand: true,
dot: true,
cwd: '<%= application.client %>/bower_components/material-design-iconic-font/dist',
dest: '<%= application.dist %>/public',
src: [
'fonts/*',
]
},
{
expand: true,
dest: '<%= application.dist %>',
src: [
'package.json',
'server/**/*'
]
}
]
},
},
env: {
test: {
NODE_ENV: 'test'
},
prod: {
NODE_ENV: 'production'
},
all: localConfig
},
injector: {
options: {
template: '<%= application.dist %>/public/index.html'
},
scripts: {
options: {
transform: function(filePath) {
filePath = filePath.replace('/dist/public/', '');
return '<script src="' + filePath + '"></script>';
},
starttag: '<!-- injector:js -->',
endtag: '<!-- endinjector -->'
},
files: {
'<%= application.dist %>/public/index.html': ['<%= application.dist %>/public/bundles/vendor.js', '<%= application.dist %>/public/bundles/code.js', ]
}
},

css: {
options: {
transform: function(filePath) {
filePath = filePath.replace('/dist/public/', '');
return '<link rel="stylesheet" href="' + filePath + '">';
},
starttag: '<!-- injector:css -->',
endtag: '<!-- endinjector -->'
},
files: {
'<%= application.dist %>/public/index.html': [
'<%= application.dist %>/public/style.min.css'
]
}
}
},
ngAnnotate: {
options: {
singleQuotes: true,
},
app: {
files: [
{
src: ['./client/app/profile/about/about.ngcontroller.js'],
expand: true,
ext: '.annotated.js',
extDot: 'last',
}
]
}
},
clean: {
dist: {
files: [{
dot: true,
src: [
'.tmp',
'<%= application.dist %>/*',
'!<%= application.dist %>/.git*',
'!<%= application.dist %>/.openshift',
'!<%= application.dist %>/Procfile'
]
}]
},
server: '.tmp'
},
buildcontrol: {
options: {
dir: 'dist',
commit: true,
push: true,
connectCommits: false,
message: 'Built %sourceName% from commit %sourceCommit% on branch %sourceBranch%'
},
heroku: {
options: {
remote: 'git@heroku.com:aqueous-stream-9919.git',
branch: 'dist',
remoteBranch: 'master'
}
}
}
});

grunt.registerTask('express-keepalive', 'Keep grunt running', function() {
this.async();
});
grunt.registerTask('serve', function(target) {
if (target === 'dist') {
return grunt.task.run(['build', 'env:all', 'env:prod', 'express:prod', 'buildcontrol']);
}
if (target === 'debug') {
return grunt.task.run([
'clean:server',
'env:all',
'injector:sass',
'concurrent:server',
'injector',
'wiredep',
'autoprefixer',
'concurrent:debug'
]);
}
grunt.task.run([
'clean:server',
'env:all',
'injector:sass',
'concurrent:server',
'injector',
'wiredep',
'autoprefixer',
'express:dev',
'wait',
'open',
'watch'
]);
});
grunt.registerTask('build', [
'clean:dist',
'connect',
'qunit',
'jshint',
'ngtemplates',
'browserify',
'sass',
'uglify',
'copy:dist',
'injector'
]);

};
})();

我缺少什么?我该如何修复?

由于Grunt Injector是一个多任务,调用injector:sass会导致Grunt从injector.sass开始查找配置对象。您的配置没有作为injector的子级的密钥sass,这解释了失败的原因。

解决此问题的两种方法:

选项A:将injector:sass替换为injector:css。这是我的猜测,但也许这就是您的意思,您的注入器配置确实有css目标,但没有sass目标。

选项B:将sass目标添加到注射器配置中,类似于以下内容:

const config = {
injector: {
sass: {
// configuration goes here to support the task `injector.sass`
}
}
}

如果您想了解更多原因,Grunt.js文档中的这一部分将解释配置目标和多任务之间的关系:https://gruntjs.com/configuring-tasks#task-配置和目标

最新更新