For now it's impossible to use default ActiveForm and GridView widgets at project which uses AMD/RequireJS for javascript insertion into page.
For example:
yii\grid\GridView::run() now has line
$view->registerJs("jQuery('#$id').yiiGridView($options);");
The solution from the outside should look like:
// Somewhere in layout:
$view->amd = true;
...
// At yii\grid\GridView::run()
$view->registerJs("$('#{$id}').yiiGridView({$options});", [
'jquery'=>'$',
'jquery.yiiGridView'=>'yiiGridView'
]);
The second method argument accepts code dependencies. The generated code for example above would be:
require(['jquery', 'jquery.yiiGridView'], function($, yiiGridView) {
$('#my-grid-view').yiiGridView({'foo':'bar'});
});
You may sight $view->amd = true; line, this signals the View object of having to use AMD-like way of JavaScript insertion into page. When it set to false, View uses default way of JS insertion (jQuery-spaghetti, as for current realisation), also the listed code dependencies would be loaded using registerScriptFile().
Will this be touched or just discussed before release? Milestone is RC
I can explain more on this topic...
$js = <<<JS
var obj = {};
JS;
This is the default way for Yii, the framework even stimulates usage of this way.
@alpharder the issue is that there are multiple JavaScript loaders: http://microjs.com/#loader so it's not wise to support one of these while not supporting others. Do you have any idea about more generic fix?
@samdark There are only three module types which are used widely - AMD, CommonJS and ES6 modules. One can read more on this topic here: http://addyosmani.com/writing-modular-js/
There are https://github.com/umdjs/umd, "UMD (Universal Module Definition) patterns for JavaScript modules that work everywhere."
https://github.com/umdjs/umd/blob/master/jqueryPluginCommonjs.js , for example.
AMD is the most used standart when we talk about async module loading, a lot of different loaders just implement it.
Still, I don't think it's good to stick to AMD and make it impossible to use others.
Postponed to future releases. I don't think we have time or will do this for 2.0 release.
out of the scope of Yii2. You can create your own Assets if you want your own custom JS implementation
Without modular, it's difficult to manage my frontend (js,css) . Yii's AssetBundle is not quit enough. Frontend tech develops fast, can Yii provide some support?
https://github.com/samdark/yii2-cookbook/blob/master/book/structure-asset-processing-with-grunt.md. Any tool could be used alike.
Most helpful comment
I can explain more on this topic...
This is the default way for Yii, the framework even stimulates usage of this way.