如何将 gulpjs 集成到 CakePhp 2.x 中?

How can integrate gulpjs in CakePhp 2.x ?

我想将gulpjs集成到Php框架中(CakePhp2.x),使用gulp实现的最佳实践是什么CakePhp 中的以下功能:

安装 Nodejs https://nodejs.org/en/download/

安装 Npm https://docs.npmjs.com/cli/install.

全局安装 gulp。 npm install --global gulp-cli

在您的根目录中创建一个 package.json 文件。

从终端导航到您的项目目录:npm install --save-dev gulp-install

在项目的根目录下创建一个 gulpfile.js。

var gulp = require('gulp'); gulp.task('default', function() {// place code for your default task here });

运行 gulp 来自终端 gulp

现在您的项目中已经安装了 gulp。 你可以在这里 https://www.npmjs.com/package/gulp-sass 参考 saas 和 gulp 任务。

同样,您可以从 http://gulpjs.com/plugins/.

找到 minify 和其他插件

有很好的 video 教程可以帮助您入门。

有一个 Node 模块可以帮助您做到这一点:https://www.npmjs.com/package/cakephp-elixir

来自文档:

If you love Elixir, but also love CakePHP, you wil love Elixir for CakePHP!

Elixir for CakePHP provides a clean, fluent API for defining basic Gulp tasks for your CakePHP application. Elixir supports common CSS and JavaScript pre-processors like Sass and Webpack. Using method chaining, Elixir allows you to fluently define your asset pipeline. For example:

elixir(function(mix) {
    mix.sass('default.scss')
       .webpack('default.js');
});

If you've ever been confused and overwhelmed about getting started with Gulp and asset compilation, you will love Elixir for CakePHP. However, you are not required to use it while developing your application. You are free to use any asset pipeline tool you wish, or even none at all.