我的 grunt 文件如下所示:
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
uglify: {
options: {
banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
},
build: {
src: 'src/**/*.js',
dest: 'dist/<%= pkg.name %>.min.js'
}
},
watch: {
js: {
files: ['src/**/*.js'],
options: {
livereload: '<%= connect.options.livereload %>'
}
},
livereload: {
options: {
livereload: '<%= connect.options.livereload %>'
},
files: [
'src/**/*.html',
'src/**/*.css',
'src/assets/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}'
]
}
},
connect: {
options: {
port: 9000,
livereload: 35729,
hostname: 'localhost'
},
livereload: {
options: {
open: true,
// base: [
// '.tmp',
// ''
// ]
middleware: function(connect) {
return [
connect.static('.tmp'),
connect().use(
'/bower_components',
connect.static('./bower_components')
),
connect().use(
'/app/styles',
connect.static('./app/styles')
),
connect.static('src')
];
}
}
}
},
copy: {
app: {
cwd: 'src', // set working folder / root to copy
src: '**/*.html', // copy all files and subfolders
dest: 'dist/', // destination folder
expand: true
},
assets: {
cwd: 'src', // set working folder / root to copy
src: 'assets/*', // copy all files and subfolders
dest: 'dist/', // destination folder
expand: true
}
},
useminPrepare: {
options: {
dest: 'dist'
},
html: 'src/index.html'
},
usemin: {
html: ['dist/index.html']
}
});
// Load the plugin that provides the "uglify" task.
// grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-usemin');
// Default task(s).
grunt.registerTask('default', ['useminPrepare', 'copy', 'concat', 'uglify', 'usemin']);
grunt.registerTask('serve', function(target) {
grunt.task.run([
'connect:livereload',
'watch'
]);
});
};
当我运行 grunt 时收到错误消息“未找到“concat”目标”。 我已经尝试了 2 个小时来解决这个问题,但没有结果请帮助我找到解决方案。
最佳答案
太晚了,但以防万一它对其他人有用:我相信 useminprepare 会自动生成一个 concat 配置并将其提供给 grunt 任务运行器,所以我认为上面的响应不太准确。
我会尝试查看 src/index.html 中的构建 block ,并检查路径是否正确指向 useminPrepare 将连接的资源。我现在正在为这样的问题而苦苦挣扎:S
关于node.js - 运行 grunt-usemin 时收到错误消息 "No "连接“找到目标”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31409150/