在Windows 8上运行咕噜声

时间:2014-07-07 12:55:43

标签: windows node.js gruntjs grunt-contrib-watch

我正试图在Windows 8机器上的现有项目上运行grunt。 我通过运行:

在全球范围内安装了grunt-cli
npm install -g grunt-cli

但是在尝试使用以下项目运行项目时

grunt develop 

我收到此错误:

Warning: Unable to write "preview.html" file <Error code: EPERM>. Use --force to continue.
Aborted due to warnings.

然后运行时

grunt develop --force

我收到此错误:

Running "less:css/main.css" <less> task
Fatal error: Unable to write "css/main.css" file <Error code: EPERM>.

您可以提供的任何帮助都是最有帮助的, 感谢。

更新1:

这是我的Gruntfile.js

module.exports = function(grunt){

  grunt.initConfig({
    watch: {
      less: {
        files: ['**/*.less', '!less/_compiled-main.less'],
        tasks: 'less'
    },
    html: {
        files: ['preview-template.html', 'js/**/*.js', 'less/**/*.less', '!less/_compiled-main.less'],
        tasks: ['includeSource', 'add-dont-edit-prefix-to-preview-html']
    },
    wysiwyg: {
        files: ['less/wysiwyg.less'],
        tasks: 'generate-wysiwyg-styles-js'
    }
},
less: {
  'css/main.css': 'less/_compiled-main.less',
  'css/wysiwyg.css': 'less/wysiwyg.less',
  options: {
    dumpLineNumbers: 'comments'
}
},
includeSource: {
  options: {
    templates: {

    },
},
dev: {
    files: {
      'preview.html': 'preview-template.html',
      'less/_compiled-main.less': 'less/main.less'
  }
}
},
connect: {
  server: {
    options: {
      base: '.',
      port: 8000
  }
}
}
});

  // Css preprocessor
  grunt.loadNpmTasks('grunt-contrib-less');
  // Watch for file changes and run other grunt tasks on change
  grunt.loadNpmTasks('grunt-contrib-watch');
  // Includes all js files in preview-template.html and saves as preview.html.
  // Includes all less files in main.less and saves as _compiled-main.less
  grunt.loadNpmTasks('grunt-include-source');
  // Static http server
  grunt.loadNpmTasks('grunt-contrib-connect');

  grunt.registerTask('generate-wysiwyg-styles-js', function(){
    var css = grunt.file.read('css/wysiwyg.css');
    css = css.replace(/\n/g, '')
    var js = '// This file is generated automatically based on wysiwyg.less - don\' edit it directly!\n';
    js += '// It needs to exist in JS form so we can include the CSS in the downloaded saved notes file';
    js += "\napp.value('wysiwygStyles', '" + css + "');";
    grunt.file.write('js/app/wysiwyg-styles.js', js)
})

  grunt.registerTask('add-dont-edit-prefix-to-preview-html', function(){
    var file = grunt.file.read('preview.html');
    var prefix = '<!-- \n\n\n\n Don\'t edit this file, edit preview-template.html instead.' + new Array(20).join('\n') + ' -->';
    file = file.replace('<!doctype html>', '<!doctype html>' + prefix)
    grunt.file.write('preview.html', file);
});

  grunt.registerTask('build-develop', [
    'includeSource',
    'less',
    'generate-wysiwyg-styles-js',
    'add-dont-edit-prefix-to-preview-html'
    ])

  grunt.registerTask('develop', [
    'build-develop',
    'connect:server',
    'watch'
    ]);
}

1 个答案:

答案 0 :(得分:1)

尝试这样的事情吗?

less: {
  files: {
    'css/main.css': 'less/_compiled-main.less',
    'css/wysiwyg.css': 'less/wysiwyg.less'
  },
  options: {
    dumpLineNumbers: 'comments'
  }
}

请注意files

后{less}数组的grunt.initConfig加法

让我知道它是否有效。