简体   繁体   English

有谁知道如何在 Laravel 4 上安装 SASS?

[英]Does anyone know how to install SASS on Laravel 4?

I am trying to run an install of SASS on Laravel 4.我正在尝试在 Laravel 4 上运行 SASS 的安装。

I am running composer and have my composer.json set up like this:我正在运行 composer 并且我的 composer.json 设置如下:

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "require": {
        "laravel/framework": "4.0.*",
        "cartalyst/sentry": "2.0.*",
    },
    "autoload": {
        "classmap": [
            "app/commands",
            "app/controllers",
            "app/models",
            "app/database/migrations",
            "app/database/seeds",
            "app/tests/TestCase.php"
        ]
    },
    "scripts": {
        "post-install-cmd": [
            "php artisan optimize"
        ],
        "post-update-cmd": [
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "post-create-project-cmd": [
            "php artisan key:generate"
        ]
    },
    "config": {
        "preferred-install": "dist"
    },
    "minimum-stability": "dev"
}

I wondered if there was a really simple way to do this in composer to add it as a project dependancy.我想知道在 Composer 中是否有一种非常简单的方法可以将其添加为项目依赖项。

The reason I want to do this is because its easier to manage and it helps in building in the long run.我想这样做的原因是因为它更易于管理并且从长远来看有助于构建。

If there is another way of doing it and installing grunt to minify the css/js then that would be even better.如果有另一种方法可以做到并安装 grunt 来缩小 css/js,那就更好了。

Thanks.谢谢。

Try laravel-sass !试试laravel-sass吧!

As all of the other projects I found were either dead, horribly broken or simply don't offer any automatic scss compiling (without having to trigger it manually every time) I ended up writing a simple tool that:由于我发现的所有其他项目要么死了,要么严重损坏,要么根本不提供任何自动 scss 编译(无需每次都手动触发),我最终编写了一个简单的工具:

  • compiles all .scss in your scss folder automatically into same-named .css files into your css folder将 scss 文件夹中的所有 .scss 自动编译为同名的 .css 文件到您的 css 文件夹中
  • is written in pure PHP !用纯 PHP 编写的
  • uses the excellent scssphp compiler and puts automatism around it使用优秀的scssphp 编译器并在它周围放置自动化
  • supports the latest SCSS syntax, currently SCSS 3.2.12支持最新的 SCSS 语法,目前SCSS 3.2.12
  • is installed via Composer with one line of code通过 Composer 安装一行代码
  • let's you define the scss and the css folder, so you always have accurate, same-name css files of your scss让我们定义 scss 和 css 文件夹,这样您就可以始终拥有准确的 scss 同名 css 文件

Installation tutorial on my blog: How to use SASS in Laravel .我博客上的安装教程:如何在 Laravel 中使用 SASS

Hi laravel developers,嗨,laravel 开发人员,

In Laravel 5 and above you can add this in require-dev, note not inside normal require.Laravel 5及更高版本中,您可以在 require-dev 中添加它,注意不在正常的 require 中。

Path: "composer.json"路径:“composer.json”

"require-dev": {
    "panique/laravel-sass": "1.0"
}

Add this line into index file.将此行添加到索引文件中。

Path: public/index.php.路径:public/index.php。

SassCompiler::run("resources/sass/", "public/css/");

Note "resources/sass" is the input file path and "public/css" output compiled path.注意“resources/sass”是输入文件路径,“public/css”是输出编译路径。 You can also keep this as simple paths like SassCompiler::run("scss/", "css/");您也可以将其保留为简单路径,例如 SassCompiler::run("scss/", "css/");

New scss files need to be added under webpacck. webpack 下需要添加新的 scss 文件。

Path: webpack.mix.js路径:webpack.mix.js

mix.js('resources/js/app.js', 'public/js')
.sass('resources/sass/app.scss', 'public/css')
.sass('resources/sass/student.scss', 'public/css')
.sass('resources/sass/website.scss', 'public/css');

I added few example likes like app,studen and website for samples.我添加了一些示例,例如应用程序、学生和网站作为示例。 Also Sass and Scss are same only few syntax difference to read more : Sass and Scss difference此外,Sass 和 Scss 相同,只有一些语法差异可以阅读更多: Sass 和 Scss 差异

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM