7

应该如何将 Foundation 与 Laravel 一起使用?

我以为我会将 Foundation 安装vendorbower install foundation. 这导致vendor/bower_components我有一个文件夹,其中包含 Foundation 和所有必需的库,例如 jQuery。

我应该添加什么gulpfile.js让 Elixir 正确解释这一点?应该可以

  • 更新 Bower 组件
  • 安装新的 Bower 包
  • 修改 Foundation Sass 变量,而不会在更新时覆盖这些变量
  • 使用指南针

在非 Laravel 项目中,我将运行 Ruby gemfoundation new my_project并手动包含编译的文件。但是,在这种情况下,该命令会创建许多不需要工作的文件。

4

2 回答 2

20

Laravel Elixir 包含 Libsass,因此您不需要 Ruby 来编译来自 Laravel 的 Foundation Sass 文件。你所需要的只是凉亭和 Laravel Elixir。此外,您不需要将文件从文件夹复制bower_componentsresources/assets文件夹。

首先按照官方说明安装 Elixir。

然后.bowerrc使用以下内容在 Laravel 项目的根目录中创建文件:

{
    "directory": "vendor/bower_components"
}

然后bower.json使用以下内容在 Laravel 项目的根目录中创建文件:

{
    "name": "laravel-and-foundation",
    "private": "true",
    "dependencies": {
        "foundation": "latest"
    }
}

然后安装凉亭和基础:

npm install --global bower
bower install # This will install Foundation into vendor/bower_components

然后resources/assets/sass/_settings.scss使用以下内容创建文件文件:

// Custom settings for Zurb Foundation. Default settings can be found at
// vendor/bower_components/foundation/scss/foundation/_settings.scss

然后resources/assets/sass/app.scss使用以下内容编辑文件文件:

@import "normalize";

@import "settings";

// Include all foundation
@import "foundation";

// Or selectively include components
// @import
//   "foundation/components/accordion",
//   "foundation/components/alert-boxes",
//   "foundation/components/block-grid",
//   "foundation/components/breadcrumbs",
//   "foundation/components/button-groups",
//   "foundation/components/buttons",
//   "foundation/components/clearing",
//   "foundation/components/dropdown",
//   "foundation/components/dropdown-buttons",
//   "foundation/components/flex-video",
//   "foundation/components/forms",
//   "foundation/components/grid",
//   "foundation/components/inline-lists",
//   "foundation/components/joyride",
//   "foundation/components/keystrokes",
//   "foundation/components/labels",
//   "foundation/components/magellan",
//   "foundation/components/orbit",
//   "foundation/components/pagination",
//   "foundation/components/panels",
//   "foundation/components/pricing-tables",
//   "foundation/components/progress-bars",
//   "foundation/components/reveal",
//   "foundation/components/side-nav",
//   "foundation/components/split-buttons",
//   "foundation/components/sub-nav",
//   "foundation/components/switches",
//   "foundation/components/tables",
//   "foundation/components/tabs",
//   "foundation/components/thumbs",
//   "foundation/components/tooltips",
//   "foundation/components/top-bar",
//   "foundation/components/type",
//   "foundation/components/offcanvas",
//   "foundation/components/visibility";

使用以下内容配置文件gulpfile.js

elixir(function(mix) {

    // Compile CSS
    mix.sass(
        'app.scss', // Source files
        'public/css', // Destination folder
        {includePaths: ['vendor/bower_components/foundation/scss']}
    );

    // Compile JavaScript
    mix.scripts(
        ['vendor/modernizr.js', 'vendor/jquery.js', 'foundation.min.js'], // Source files. You can also selective choose only some components
        'public/js/app.js', // Destination file
        'vendor/bower_components/foundation/js/' // Source files base directory
    );


});

要构建只需遵循官方文档:

gulp # Run all tasks...
gulp --production # Run all tasks and minify files
gulp watch # Watch for changes and run all tasks on the fly

您的编译文件将位于public/css/app.csspublic/js/app.js

要更新到最新的 Zurb Foundation 版本,只需运行:

bower update
于 2015-06-27T09:28:31.577 回答
1

将 Fundation > scss 文件夹复制到 resources > assets 文件夹,将 scss 重命名为 sass,在您的 gulpfile.js 中添加以下内容

elixir(function(mix) {
    mix.sass('foundation.scss');
});

运行 gulp,它将在 public > css 文件夹中生成foundation.css 文件,将该文件包含在您的项目中。

对于 js 文件,您可以简单地使用类似这样的东西来复制文件

mix.copy('resources/assets/foundation/js/app.js', 'public/js/app.js');
于 2015-06-26T02:57:26.170 回答