E
E
Externus2015-05-20 03:15:33
Yii
Externus, 2015-05-20 03:15:33

How to set addresses to resources in css when using resource compression in Yii2?

Good day.
Compressing resources, using the method described by
https://github.com/yiisoft/yii2/blob/master/docs/g...
Faced a problem.
For example, the project has a single bundle Test

class TestAsset extends AssetBundle
{
    
    public $sourcePath = '@app/assets-resources/test';
    public $css = [
        '1.css'
    ];
    public $js = [
    ];
    public $depends = [

    ];
}

Which contains 1 css file, and in the folder next to the css is the font that is included in this css
@font-face {
  font-family: 'Glyphicons Halflings';
  src: url('glyphicons-halflings-regular.eot');
}

After minimizing according to this configuration
(as it turned out later, @webroot should be set like this Yii::setAlias('@webroot', __DIR__ . '/../../www'))
Yii::setAlias('@webroot', '../www');
Yii::setAlias('@web', '/');

return [
    // Adjust command/callback for JavaScript files compressing:
    'jsCompressor' => 'java -jar compiler.jar --js {from} --js_output_file {to}',
    // Adjust command/callback for CSS files compressing:
    'cssCompressor' => 'java -jar yuicompressor.jar --type css {from} -o {to}',
    // The list of asset bundles to compress:
    'bundles' => [
        'app\assets\TestAsset',
    ],
    // Asset bundle for compression output:
    'targets' => [
        'all' => [
            'class' => 'yii\web\AssetBundle',
            'sourcePath' => null,
            'basePath' => '@webroot/assets',
            'baseUrl' => '@web/assets',
//            'js' => 'all-{hash}.js',
            'css' => 'all-{hash}.css',
        ],
    ],
    // Asset manager configuration:
    'assetManager' => [
        'basePath' => '@webroot/assets',
        'baseUrl' => '@web/assets',
    ],
]; 

We have all-{hash}.css in the @webroot/assets
folder and the folder into which all the contents of the @app/assets-resources/test
all-{hash}.css folder have been copied with such content
@font-face{font-family:'Glyphicons Halflings';src:url('../../C:/Dropbox/_htdocs/site/www/assets/43e204a5/glyphicons-halflings-regular.eot')}a{color:#333}

Accordingly, at ../../C:/Dropbox/_htdocs/site/www/assets/43e204a5/glyphicons-halflings-regular.eot the browser cannot get the required resource, how to fix this problem?
Thanks

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Externus, 2015-05-20
@Externus

After a long night, the problem was almost solved.
In the configuration for the minimizer, I set alias webroot as
yii
\console\controllers\AssetController when setting a relative address ('@webroot', '../www' ) it cannot "cut" the relative address from css files, because to. in css they are set absolutely, and in elias relatively

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question