Grunt 由于警告而中止

Grunt aborted due to warnings

我已经在本地机器上安装了 "npm"。在我的 Gruntfile.js 目录中,我以这种方式安装 grunt:

  1. npm install grunt
  2. npm install -g grunt-cli
  3. grunt watch

tasker 是 运行,但我收到了这些警告:

这是我的 gruntfile.js 文件

module.exports = function (grunt) {
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),

        sass: {
            dist: {
                options: {
                    style: 'compact',
                    cacheLocation: 'assets/sass/.cache-location',
                },
                files: [{
                    'assets/css/dx-epb-admin.css': 'assets/css/scss/dx-epb-admin.scss',
                    'assets/css/dx-epb-public.css': 'assets/css/scss/dx-epb-public.scss',
                    'assets/css/dx-epb-grid.css': 'assets/css/scss/dx-epb-grid.scss',
                }],
            },
        },

        autoprefixer:{
            dist: {
                files: {
                    'assets/css/dx-epb-admin.css': 'assets/css/dx-epb-admin.css',
                    'assets/css/dx-epb-admin-new.css': 'assets/css/dx-epb-admin-new.css',
                    'assets/css/dx-epb-public.css': 'assets/css/dx-epb-public.css',
                    'assets/css/dx-epb-grid.css': 'assets/css/dx-epb-grid.css',
                },
            },
        },

        watch: {
            scripts: {
                files: ['assets/js/src/*.js'],
                tasks: ['jshint', 'uglify'],
            },
            css: {
                files: [ 'assets/css/**/*.scss', 'assets/css/*.css' ],
                tasks: ['sass', 'autoprefixer', 'cssmin'],
            },
        },

        cssmin: {
            options: {
                shorthandCompacting: false,
                roundingPrecision: -1
            },
            target: {
                files: {
                    'assets/css/dx-epb-admin.min.css': ['assets/css/dx-epb-admin.css'],
                    'assets/css/dx-epb-admin-new.min.css': ['assets/css/dx-epb-admin-new.css'],
                    'assets/css/dx-epb-public.min.css': ['assets/css/dx-epb-public.css'],
                    'assets/css/dx-epb-grid.min.css': ['assets/css/dx-epb-grid.css'],
                }
            }
        },

        uglify: {
            target: {
                files: {                    
                    'assets/js/dx-epb-admin.min.js':
                    [
                        'assets/js/src/dx-epb-admin.js',
                    ],
                    'assets/js/dx-epb-admin-new.min.js':
                    [
                        'assets/js/src/dx-epb-admin-new.js',
                    ],
                    'assets/js/dx-epb-admin-save.min.js':
                    [
                        'assets/js/src/dx-epb-admin-save.js',
                    ],
                    'assets/js/dx-epb-control.min.js':
                    [
                        'assets/js/src/dx-epb-control.js',
                    ],
                    'assets/js/dx-epb-media-upload.min.js':
                    [
                        'assets/js/src/dx-epb-media-upload.js',
                    ],
                    'assets/js/dx-epb-public.min.js':
                    [
                        'assets/js/src/dx-epb-public.js',
                    ],
                    'assets/js/dx-epb-tinymce-button.min.js':
                    [
                        'assets/js/src/dx-epb-tinymce-button.js',
                    ]
                }
            }
        },

        jshint: {
            all: ['Gruntfile.js', 'assets/js/scripts.js'],
        },
    });

    grunt.loadNpmTasks('grunt-sass');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-contrib-jshint');
    grunt.loadNpmTasks('grunt-contrib-cssmin');
    grunt.loadNpmTasks('grunt-autoprefixer');
    grunt.loadNpmTasks('grunt-contrib-uglify');

    grunt.registerTask('default', ['watch']);
    grunt.registerTask('css', ['sass', 'autoprefixer']);
    grunt.registerTask('minify', ['cssmin']);
    grunt.registerTask('minifyjs', ['uglify']);
};

您需要安装列出的所有缺少的 g运行t 任务。如果你有一个 package.json 文件列出了所需的依赖项,你需要做的就是在同一目录中 运行 npm install

否则从命令行手动安装每一个,如:

    npm install grunt-sass
    npm install grunt-contrib-watch
    npm install grunt-contrib-jshint
    npm install grunt-contrib-cssmin
    npm install grunt-autoprefixer
    npm install grunt-contrib-uglify