Node.js   发布时间:2022-04-24  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了gruntjs – Grunt在服务器上观看LiveReload大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在服务器(非本地)上开发wordpress站点.每当我修改sass文件时,我想在浏览器中刷新页面.我已经列出了一些咕噜咕噜的任务,但是现在我只想让它在任何修改上刷新.现在,它会在文件修改时捕获,但不会刷新页面.

Gruntfile:

@H_189_9@module.exports = function(grunt) { // Project configuration. grunt.initConfig({ pkg: grunt.file.readJSON('package.json'),watch: { scripts: { options: { livereload: true },files: ['**/*.scss'],//tasks: ['criticalcss:front','criticalcss:page','cssmin','postcss'],} },postcss: { options: { processors: [ require('autoprefixer')({Browsers: 'last 6 versions'}),// add vendor prefixes //require('cssnano')() // minify the result ] },dist: { src: 'style.css',dest: 'style.css' } },criticalcss: { front : { options: { url: "https://grandeurflooring.ca/grand_dev/",minify: true,width: 1500,height: 900,outputfile: "critical_css/critical-front.css",filename: "style.css",buffer: 800*1024,ignoreConsole: true } },page : { options: { url: "https://grandeurflooring.ca/grand_dev/sample-page/",outputfile: "critical_css/critical-page.css",ignoreConsole: true } } },cssmin: { target: { files: [{ expand: true,cwd: 'critical_css',src: ['*.css','!*.min.css'],dest: 'critical_css',ext: '.min.css' }] } } }); // Load the plugin that provides the "critical" task. grunt.loadNpmTasks('grunt-criticalcss'); // Load the plugin that provides the "cssmin" task. grunt.loadNpmTasks('grunt-contrib-cssmin'); // Load the plugin that provides the "watch" task. grunt.loadNpmTasks('grunt-contrib-watch'); // Load the plugin that provides the "PostCSS" task. grunt.loadNpmTasks('grunt-postcss'); // Critical task. grunt.registerTask('critical',['criticalcss:front']); };

在footer.PHP中,在wp_footer()之前,我把脚本放了:

<script src="http://localhost:35729/livereload.js"></script>

解决方法

您可以配置Grunt以在dist目录中查看已编译的css文件,每次重新编译Sass时都会更新该文件.

这是我的手表配置,它实现了你想要的:

watch: {
  options: {
    livereload: true,},html: {
    files: ['index.html'],js: {
    files: ['js/**/*.js'],tasks: ['jshint'],sass: {
    options: {
      livereload: false
    },files: ['css/scss/**/*.scss'],tasks: ['sass'],css: {
    files: ['dist/css/master.css'],tasks: []
  }
}

可能需要将spawn:false更改为spawn:true,具体取决于您的设置.

编辑:此外,您可以使用grunt-contrib-watch插件,它允许您:

插件包含许多其他选项,可用于实时重新加载,观看等,您可能会觉得这些选项很有用.

大佬总结

以上是大佬教程为你收集整理的gruntjs – Grunt在服务器上观看LiveReload全部内容,希望文章能够帮你解决gruntjs – Grunt在服务器上观看LiveReload所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。