【问题标题】:How to fix 'SyntaxError: Unexpected identifier Warning: Task "sass" not found' when loading gruntfile.js tasks?加载 gruntfile.js 任务时如何修复“语法错误:意外标识符警告:找不到任务“sass”?
【发布时间】:2019-11-29 08:38:33
【问题描述】:

我无法开始使用 grunt sass 进行 scss 到 css 编译。

这是我的 gruntfile.js:

const sass = require('node-sass');

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

grunt.initConfig({
   sass: {
      options: {
          implementation: sass,
          sourceMap: true
      },
      dist: {
          files: {
              'style.css':'style.scss'
          }
      }
   }

   grunt.registerTask('default', ['sass']);
 });`

【问题讨论】:

    标签: css sass gruntjs syntax-error


    【解决方案1】:

    registerTask()initConfig() 中。它需要移到外面:

    const sass = require('node-sass');
    
    require('load-grunt-tasks')(grunt);
    
    grunt.initConfig({
        sass: {
            options: {
                implementation: sass,
                sourceMap: true
            },
            dist: {
                files: {
                    'main.css': 'main.scss'
                }
            }
        }
    });
    
    grunt.registerTask('default', ['sass']);
    

    参考:https://www.npmjs.com/package/grunt-sass

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-05
      • 1970-01-01
      • 1970-01-01
      • 2015-02-13
      • 1970-01-01
      • 1970-01-01
      • 2016-03-02
      • 2014-01-30
      相关资源
      最近更新 更多