我正在開發一個服務器上的WordPress網站(不是本地)。當我修改一個sass文件時,我想在瀏覽器中刷新頁面。我列出了一些煩人的任務,但現在我只想讓它在任何sass修改時刷新。現在,只要文件被修改,它就會捕獲,但不會刷新頁面。Grunt在服務器上觀看LiveReload網站
Gruntfile:
module.exports = function(grunt) {
\t // Project configuration.
\t grunt.initConfig({
\t \t pkg: grunt.file.readJSON('package.json'),
\t \t
\t \t watch: {
\t \t \t scripts: {
\t \t \t \t options: { livereload: true },
\t \t \t \t files: ['**/*.scss'],
\t \t \t \t //tasks: ['criticalcss:front', 'criticalcss:page', 'cssmin', 'postcss'],
\t \t \t }
\t \t },
\t \t
\t \t postcss: {
\t \t \t options: {
\t \t \t \t processors: [
\t \t \t \t \t require('autoprefixer')({browsers: 'last 6 versions'}), // add vendor prefixes
\t \t \t \t \t //require('cssnano')() // minify the result
\t \t \t \t ]
\t \t \t },
\t \t \t dist: {
\t \t \t \t src: 'style.css',
\t \t \t \t dest: 'style.css'
\t \t \t }
\t \t },
\t
\t \t criticalcss: {
\t \t \t front : {
\t \t \t \t options: {
\t \t \t \t \t url: "https://grandeurflooring.ca/grand_dev/",
\t \t \t \t \t minify: true,
\t \t \t \t \t width: 1500,
\t \t \t \t \t height: 900,
\t \t \t \t \t outputfile: "critical_css/critical-front.css",
\t \t \t \t \t filename: "style.css",
\t \t \t \t \t buffer: 800*1024,
\t \t \t \t \t ignoreConsole: true
\t \t \t \t }
\t \t \t },
\t \t \t page : {
\t \t \t \t options: {
\t \t \t \t \t url: "https://grandeurflooring.ca/grand_dev/sample-page/",
\t \t \t \t \t minify: true,
\t \t \t \t \t width: 1500,
\t \t \t \t \t height: 900,
\t \t \t \t \t outputfile: "critical_css/critical-page.css",
\t \t \t \t \t filename: "style.css",
\t \t \t \t \t buffer: 800*1024,
\t \t \t \t \t ignoreConsole: true
\t \t \t \t }
\t \t \t }
\t \t },
\t \t
\t \t cssmin: {
\t \t \t target: {
\t \t \t \t files: [{
\t \t \t \t expand: true,
\t \t \t \t cwd: 'critical_css',
\t \t \t \t src: ['*.css', '!*.min.css'],
\t \t \t \t dest: 'critical_css',
\t \t \t \t ext: '.min.css'
\t \t \t \t }]
\t \t \t }
\t \t }
\t });
\t // Load the plugin that provides the "critical" task.
\t grunt.loadNpmTasks('grunt-criticalcss');
\t // Load the plugin that provides the "cssmin" task.
\t grunt.loadNpmTasks('grunt-contrib-cssmin');
\t // Load the plugin that provides the "watch" task.
\t grunt.loadNpmTasks('grunt-contrib-watch');
\t // Load the plugin that provides the "PostCSS" task.
\t grunt.loadNpmTasks('grunt-postcss');
\t // Critical task.
\t grunt.registerTask('critical', ['criticalcss:front']);
};
在footer.php,wp_footer()之前,我把劇本:
<script src="http://localhost:35729/livereload.js"></script>
如果要將消息推送到瀏覽器並使其重新加載頁面,則需要使用websocket或服務器發送的事件。或者您可以使用AJAX進行投票。但我建議不要添加強制頁面重新加載的代碼。當您的網站在線時,您仍然希望刪除代碼。 –
雖然我正在服務器上開發,所以我希望啓動並運行,即使這意味着稍後再刪除代碼。如果你碰巧知道如何做到這一點的實施,它的工作原理,你會介意發佈一個答案? –