1

当我在开发文件的任意位置单击保存时,看起来它没有重新复制我的文件(所以我想立即重新复制到生产文件夹中)。这是我的 Gruntfile.js 中的一部分。

该文件的位置:/development/Gruntfile.js

我想在哪里复制一些文件:/production

[...]

copy: {
  watch: {
    options: {
      livereload: true
    },
    files: [
      {expand: true, src: ['css/*'], dest: '../production/', filter: 'isFile'},
      {expand: true, src: ['js/*'], dest: '../production/', filter: 'isFile'},
      {expand: true, src: ['js/vendor/*'], dest: '../production/', filter: 'isFile'},

      {expand: true, src: ['images/**'], dest: '../production/'},
      {expand: true, src: ['public/**'], dest: '../production/'},

      {expand: true, src: ['.htaccess', '404.html', 'apple-touch-icon-precomposed.png', 'crossdomain.xml', 'favicon.ico', 'humans.txt', 'index.html', 'index.php', 'LICENSE.md', 'README.md', 'robots.txt'], dest: '../production/'}
    ]
  }
},

php: {
  watch: {
    options: {
      livereload: true,
      bin: 'C:/php/php.exe',
      ini: 'C:/php/php.ini',
      base: '../production',
      port: 8000
    }
  }
},

watch: {
  options: {
    livereload: true
  },
  site: {
    files: ['*.html', '*.php', 'public/*.html', 'public/*.php'],
    tasks: ['php'],
    options: {
      spawn: false
    }
  }
}

[...]

grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-php');
grunt.loadNpmTasks('grunt-contrib-watch');

grunt.registerTask('default', ['uglify', 'replace', 'stylus', 'cssmin', 'copy:watch', 'php:watch', 'watch']);

我总是需要重新启动脚本,将文件重新发送到“生产”文件夹中。

谢谢您的帮助!

更新

我做了一个改变解决方案:一切都发生在开发文件夹中,如果我愿意,我可以使用命令行推送到生产文件夹。这样我在开发文件夹中的本地 PHP 网络服务器中看到最终产品,而不是生产。

grunt.registerTask('default', ['uglify', 'replace', 'stylus', 'cssmin', 'php:watch', 'watch']);
grunt.registerTask('copytoproduction', ['copy']);
4

0 回答 0