gpt4 book ai didi

javascript - grunt 在完成 sass 任务之前继续执行下一个任务

转载 作者:行者123 更新时间:2023-12-03 12:22:18 24 4
gpt4 key购买 nike

这是我的 grunt 文件:

'use strict';

var path = require('path');

module.exports = function (grunt) {

require('load-grunt-tasks')(grunt);

require('time-grunt')(grunt);
console.log(path.basename());
grunt.initConfig({
yeoman: {
app: require('./bower.json').appPath || 'app',
build: 'dist',
name: require('./bower.json').name
},
html2js: {
options: {
module: '<%= yeoman.name %>-templates',
base: 'app'
},
main: {
src: ['<%= yeoman.app %>/**/*.tpl.html'],
dest: '<%= yeoman.build %>/templates.js'
}
},
sass: {
dist: {
src: '<%= yeoman.build %>/<%= yeoman.name %>.scss',
dest: '<%= yeoman.build %>/<%= yeoman.name %>.css'
}
},
imageEmbed: {
dist: {
files: [{
expand: true,
cwd: '<%= yeoman.app %>/styles/',
src: ['*.{scss,css}'],
dest: '.tmp/'
}]
}
},
cssmin: {
dist: {
src: '<%= yeoman.build %>/<%= yeoman.name %>.css',
dest: '<%= yeoman.build %>/<%= yeoman.name %>.min.css'
}
},
concat: {
css: {
src: ['.tmp/**/*.scss', '.tmp/**/*.css'],
dest: '<%= yeoman.build %>/<%= yeoman.name %>.scss'
},
js: {
src: ['<%= yeoman.build %>/templates.js', '<%= yeoman.app %>/scripts/app.js', '<%= yeoman.app %>/scripts/**/*.js'],
dest: '<%= yeoman.build %>/<%= yeoman.name %>.js'
}
},
uglify: {
complete: {
src: '<%= yeoman.build %>/<%= yeoman.name %>.js',
dest: '<%= yeoman.build %>/<%= yeoman.name %>.min.js'
}
},
karma: {
options: {
configFile: 'karma.conf.js'
},
unit: {
singleRun: true
}
}
});


grunt.registerTask('build', [
'html2js',
'imageEmbed',
'concat:css',
'sass',
'cssmin'
'concat:js',
'uglify',
]);
grunt.registerTask('test', [
'karma:unit'
]);
};

运行 grunt build 时,出现以下错误:

Running "sass:dist" (sass) task

Running "cssmin:dist" (cssmin) task

Destination not written because minified CSS was empty.

当我分别运行每个任务时,没有错误。我认为 sass 任务在下一个任务开始之前还没有完成。有谁知道为什么会这样?

谢谢。

最佳答案

这可能是因为 sass 任务是异步运行的,我在 livereload 中遇到过类似的问题。

尝试这样的事情并在两个任务之间注册它:

  grunt.registerTask('wait', function () {
grunt.log.ok('Waiting for server reload...');
var done = this.async();
setTimeout(function () {
grunt.log.writeln('Done waiting!');
done();
}, 1500);
});

http://gruntjs.com/api/inside-tasks

关于javascript - grunt 在完成 sass 任务之前继续执行下一个任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25032956/

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