Closed Pwuts closed 1 year ago
What if you have images there references from stylesheets?
Then it could make sense to publish first, yes... but not in my current use case. Can you help me to solve issue 3 (and maybe 1)?
Sure. This would help copying only what's needed i.e. solve case 1: https://github.com/yiisoft/yii2/blob/5406e5dad3eaa4e9d58f65bb565d37adc4307f3b/framework/web/AssetManager.php#L452 These options could be set on a concrete bundle level via publishOptions
.
The source folder @app/scss
:
scss
includes
_file1.scss
_file2.scss
lib
_file3.scss
_file4.scss
_variables.scss
index.scss
utils.scss
In this case, after conversion, index.css
and utils.css
are imported/used by views and layouts. The source files index.scss
and utils.scss
import the other files such as _variables.scss
and also a library located somewhere in vendor/
(with a relative path, ../vendor/author/lib/file.scss
).
Importing that library still fails because the source files are moved before conversion. I can solve it like this in the config:
// config/web.php
$appRoot = dirname(__DIR__);
/* ... */
$config['components']['assetManager']['converter'] => [
'commands' => [
'scss' => ['css', "sass --style=compressed --load-path=$appRoot/vendor {from} {to}"],
],
];
It works, but it feels like a bodge. It would be nice if Yii had a better way to prevent this problem, even if it was as simple as alias conversion in the command string e.g. allowing sass --load-path=@app/vendor {from} {to}
.
https://github.com/yiisoft/yii2/blob/5406e5dad3eaa4e9d58f65bb565d37adc4307f3b/framework/web/AssetBundle.php#L180-L182
This executes:
sourcePath
is set andbasePath
is not, the asset is publishedThe problem
$sourcePath
and$basePath
are set: instead of converting from$sourcePath
into$basePath
, it completely ignores$basePath
(which is not explicitly documented) and publishes to a hashed asset folder in the webroot.index.scss
which importsbase.scss
and../vendor/package/dep.scss
. Because the first step is to copyindex.scss
to the webroot, the relative imports will break and conversion will subsequently fail.Two possible solutions:
sass
will accept both an input and output path, it makes sense to me to just callsass --style=compressed {sourcePath} {basePath}
.