The Wayback Machine - https://web.archive.org/web/20200718065337/https://github.com/yiisoft/yii2/issues/17994
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AssetBundle is linking scss files in the HTML head #17994

Open
neoacevedo opened this issue Apr 23, 2020 · 2 comments
Open

AssetBundle is linking scss files in the HTML head #17994

neoacevedo opened this issue Apr 23, 2020 · 2 comments

Comments

@neoacevedo
Copy link

@neoacevedo neoacevedo commented Apr 23, 2020

Additional info

Q A
Yii version 2.0.34
PHP version 7.4.5
Operating system N/A

I'm following this guide to convert scss files to css files.

In the css array from my AppAsset I have to add scss/myFile.scss to yii runs the converter command, but with this, the AssetBundle renders into the HTML head section the link to the scss file, so I have to add into the same array, the css file css/myFile.css.

@samdark
Copy link
Member

@samdark samdark commented Apr 24, 2020

Would you please put together a simple test case to reproduce it starting with basic app template and making minimal amount of changes? Thanks.

@yiisoft yiisoft deleted a comment from yii-bot Apr 24, 2020
@neoacevedo
Copy link
Author

@neoacevedo neoacevedo commented Apr 24, 2020

Frontend App Advanced main config:

<?php

$params = array_merge(
        require __DIR__ . '/../../common/config/params.php', require __DIR__ . '/../../common/config/params-local.php', require __DIR__ . '/params.php', require __DIR__ . '/params-local.php'
);

$from = dirname(__DIR__) . '/themes/grayscale/scss/grayscale.scss';
$to = filter_input(INPUT_SERVER, 'DOCUMENT_ROOT') . "/web/themes/grayscale/css/grayscale.css";

return [
    'id' => 'app-frontend',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log'],
    'controllerNamespace' => 'frontend\controllers',
    'components' => [
        'assetManager' => [
            'bundles' => [
                #'yii\web\JqueryAsset' => [
                #    'sourcePath' => null, 'js' => [],
                #],
                'yii\bootstrap\BootstrapAsset' => [
                    'sourcePath' => null, 'css' => [],
                ],
                'yii\bootstrap\BootstrapPluginAsset' => [
                    'sourcePath' => null, 'js' => [],
                ],
                'yii\jui\JuiAsset' => [
                    'sourcePath' => null, 'css' => [], 'js' => [],
                ],
                '\rmrevin\yii\fontawesome\AssetBundle' => [
                    'sourcePath' => null, 'css' => [],
                ],
            ],
            'converter' => [
                'class' => 'yii\web\AssetConverter',
                'commands' => [
                    'scss' => ['scss', "sass $from $to --source-map"]
                ],
                'forceConvert' => true
            ],
            'appendTimestamp' => true,
        ],
        'view' => [
            'theme' => [
                #'class' => yii\base\Theme::class,
                'basePath' => '@app/themes/grayscale',
                'pathMap' => ['@app/views' => '@app/themes/grayscale'],
                'baseUrl' => '@web/themes/grayscale',
            ]
        ],
        'request' => [
            'csrfParam' => '_csrf-frontend',
            'baseUrl' => '/web',
        ],
        'user' => [
            'identityClass' => 'common\models\User',
            'enableAutoLogin' => true,
            'identityCookie' => ['name' => '_identity-frontend', 'httpOnly' => true],
        ],
        'session' => [
// this is the name of the session cookie used for login on the frontend
            'name' => 'advanced-frontend',
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
                [
                    'class' => yii\log\SyslogTarget::class,
                    'levels' => ['error', 'warning']
                ]
            ],
        ],
        'errorHandler' => [
            'errorAction' => 'site/error',
        ],
        'urlManager' => [
            'class' => 'yii\web\UrlManager',
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            #'suffix' => '.html',
            'rules' => [
                // tecnorecicla
                'requirement/<action:\w+>' => '/web/requirement/<action>',
            ],
        ],
    ],
    'params' => $params,
];

Frontend App Asset:

<?php

/**
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

namespace frontend\assets;

use Yii;
use yii\web\AssetBundle;
use yii\helpers\FileHelper;

/**
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @since 2.0
 */
class ThemeAsset extends AssetBundle
{

    /**
     * {@inheritdoc}
     */
    public $sourcePath = '@app/themes/grayscale'; //maybe set also as maybe unset

    /**
     * {@inheritdoc}
     */
    public $basePath = "@webroot/themes/grayscale";

    /**
     * {@inheritdoc}
     */
    public $baseUrl = '@web/themes/grayscale';

    /**
     * {@inheritdoc}
     */
    public $css = [
        'vendor/bootstrap/css/bootstrap.min.css',
        'vendor/fontawesome-free/css/all.min.css',
        "scss/grayscale.scss", // this is the scss inside @frontend/themes/grayscale/scss. This is rendered as <link href="/web/themes/grayscale/scss/grayscale.scss" rel="stylesheet">
        'css/grayscale.css', // this is the compiled scss inside @webroot/themes/grayscale/css
        [
            'href' => "favicon.ico",
            'rel' => 'icon',
            'sizes' => '16x16',
        ],
    ];

    /**
     * {@inheritdoc}
     */
    public $js = [
        #'vendor/jquery/jquery.min.js',
        'vendor/bootstrap/js/bootstrap.bundle.min.js',
        'js/grayscale.min.js',
        "vendor/jquery-easing/jquery.easing.min.js"
    ];

    /**
     * {@inheritdoc}
     */
    public $depends = [
        'yii\web\YiiAsset',
        #'yii\bootstrap\BootstrapAsset',
        #'yii\bootstrap\BootstrapPluginAsset',
    ];

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants
You can’t perform that action at this time.