kartik-v / yii2-widget-datepicker

Enhanced Yii2 wrapper for the bootstrap datepicker plugin (sub repo split from yii2-widgets)
http://demos.krajee.com/widget-details/datepicker
Other
112 stars 91 forks source link

Asset compression and language problem #133

Closed dan-developer closed 5 years ago

dan-developer commented 7 years ago

When using the Yii 2 assets compressor it's all compressed into one file only, so the language file is loading when the widget is called, then the following error occurs:

not-found

the problem is here: https://github.com/kartik-v/yii2-widget-datepicker/blob/master/DatePicker.php#L221

my assets config:

<?php
/**
 * @link https://www.tubaron.com.br
 * @copyright Copyright (c) 2016-2017 Tubaron LTDA
 * @author Anderson Scouto da Silva <and.dan19@gmail.com>
 */

/**
 * Configuration file for the "yii asset" console command.
 */

// In the console environment, some path aliases may not exist. Please define these:
Yii::setAlias('@webroot', __DIR__ . '/../web');
Yii::setAlias('@web', '/');

return [
    'jsCompressor' => 'java -jar bin/compiler/assets/closure-compiler-v20170218.jar --js {from} --js_output_file {to} --jscomp_off=uselessCode',
    'cssCompressor' => 'java -jar bin/compiler/assets/yuicompressor-2.4.8.jar --type css {from} -o {to}',
    'bundles' => [
        'app\themes\material\MaterialThemeAsset',

        'tubaron\assets\TubaronAsset',
        'tubaron\assets\LightGalleryAsset',
        'tubaron\assets\JqueryGrowlAsset',
        'tubaron\phoneinput\PhoneInputAsset',
        'tubaron\widgets\ajaxmodalform\ModalAsset',
        'tubaron\assets\waitme\WaitMeAsset',
        'tubaron\assets\SpinJsAsset',
        'tubaron\assets\LaddaButtonsAsset',
        'tubaron\assets\SweetAlertAsset',
        'tubaron\assets\JcropAsset',
        'tubaron\assets\LightGalleryAsset',
        'tubaron\assets\SpinJsAsset',
        'tubaron\assets\TextareaAutosizeAsset',
        'tubaron\modules\notification\widgets\NotificationAsset',
        'tubaron\modules\notification\Html5DesktopNotification',
        'tubaron\widgets\AvatarImageUploadAsset',
        'tubaron\widgets\cookiemessage\CookieMessageAsset',
        'tubaron\widgets\mention\MentionAsset',
        'tubaron\widgets\OpenWeatherMapAsset',
        'tubaron\widgets\SelectizeAsset',
        'tubaron\widgets\DualListboxAsset',
        'tubaron\web\OutdatedBrowserAsset',
        'tubaron\web\JsStorageApiAsset',

        'samdark\webshell\JqueryTerminalAsset',

        'kartik\file\SortableAsset',
        'kartik\datecontrol\DateControlAsset',
        'kartik\select2\ThemeKrajeeAsset',
        'kartik\select2\ThemeBootstrapAsset',
        'kartik\select2\Select2Asset',
        'kartik\date\DatePickerAsset',
        'kartik\datecontrol\DateFormatterAsset',
        'kartik\file\FileInputAsset',
        'kartik\file\DomPurifyAsset',
        'kartik\grid\ActionColumnAsset',
        'kartik\grid\CheckboxColumnAsset',
        'kartik\grid\EditableColumnAsset',
        'kartik\grid\ExpandRowColumnAsset',
        'kartik\grid\GridExportAsset',
        'kartik\grid\GridGroupAsset',
        'kartik\grid\GridResizeStoreAsset',
        'kartik\grid\GridToggleDataAsset',
        'kartik\grid\RadioColumnAsset',
        'kartik\grid\GridResizeColumnsAsset',
        'kartik\grid\GridViewAsset',
        'kartik\dynagrid\DynaGridAsset',
        'kartik\dynagrid\DynaGridDetailAsset',
        'kartik\base\WidgetAsset',
        'kartik\sortable\SortableAsset',
        'kartik\detail\DetailViewAsset',
        'kartik\dialog\DialogAsset',
        'kartik\dialog\DialogBootstrapAsset',
        'kartik\form\ActiveFormAsset',
        'kartik\icons\FontAwesomeAsset',

        'yii\jui\JuiAsset',
        'yii\validators\ValidationAsset',
        'yii\widgets\PjaxAsset',
        //'yii\widgets\MaskedInputAsset', // "Parse error. '}' expected static || null !== test.fn && void 0 !== testPos.input ? static && null !== test.fn && void 0 !== testPos.input && (static = !1" ao comprimir
        'yii\widgets\ActiveFormAsset',
        'yii\grid\GridViewAsset',
        'yii\web\YiiAsset',
        'yii\web\JqueryAsset',
        'yii\bootstrap\BootstrapPluginAsset',

    ],
    'targets' => [
        'all' => [
            'class' => 'yii\web\AssetBundle',
            'basePath' => '@webroot',
            'baseUrl' => '@web',
            'js' => 'assets/all-{hash}.js',
            'css' => 'assets/all-{hash}.css',
        ],
    ],
    'assetManager' => [
        'basePath' => '@webroot/assets',
        'baseUrl' => '@web/assets',
        'hashCallback' => function ($path) {
            return hash('md4', $path);
        },
    ],
];
--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/43912273-asset-compression-and-language-problem?utm_campaign=plugin&utm_content=tracker%2F8181363&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F8181363&utm_medium=issues&utm_source=github).
xenogenesi commented 7 years ago

I've the same issue, any workaround beside copying the language file in the expected path?

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

PaulVanSchayck commented 3 years ago

Anyone ever coming across this problem. This is the least ugly workaround I could come up with:

$config['components']['assetManager'] = [
        'bundles' => ArrayHelper::merge(
            require (__DIR__ . '/' . 'assets-prod.php'),
            [
                'kartik\\date\\DatePickerAsset' => [
                    'sourcePath' => '@vendor/kartik-v/yii2-widget-datepicker/src/assets',
                ]
            ]
        )
    ];

Basically, it works by overriding the automatically generated assets-prod.php, by resetting the path again to the asset. This will allow the browser to correctly load the language JS file.