D
D
Dmitry2017-08-17 16:29:16
Yii
Dmitry, 2017-08-17 16:29:16

How to connect yii2 resources?

There was a problem with transferring the site from yii1 to yii2, I can’t connect js scripts in any way.
First, I did as usual, in a file with a class inherited from AssetBundle, I registered all the scripts and styles that I found on the page. Looked simply through the source code.
I tried to run it - the styles are connected, but the scripts do not want to be connected. Neither fancybox nor carousel( cycle2 ) works.
It is noteworthy that in the old site nothing is connected for these plugins. Began to search. I found the "dev" directory, where there was a Gruntfile.js file and a bunch of directories, where there were js, and css, and scss, and the like.
I have never worked with Grunt. I read the documentationand I realized, if I'm not mistaken, that grunt helps to combine the necessary scripts and minimize and it will be enough to include the generated files.
The site also has a separate directory with js scripts that are connected on the page. If you delete / rename it, then nothing works on the old site either. So everything should be connected through these scripts. I opened one of the js files, through a search in the file I found a mention of both fancybox and carousels, it turns out that it is enough to connect them and everything should work. But I couldn't connect anything.
I tried to connect Grunt in a new project ( https://yii2-cookbook.readthedocs.io/structure-ass... but again, the styles are included, and js does not want to work. At the same time, I threw a bunch of plugins into the project that I don’t need .
Tell me how to solve the problem?
PS I tried to move the dev directory along with the Gruntfile.js file and a bunch of others to a new project. I changed the paths to files and directories in Gruntfile.js, but I did not achieve a positive result.
Grunfile.js content

// Обязательная обёртка
module.exports = function(grunt) {

  // Конфигурация
  grunt.initConfig({
    // Пути к файлам и папкам
    configDir: 'config',

    sassDir: 'sass',
    sassFiles: '<%= sassDir %>' + '/main.scss',
    cssDir: '../css',

    jsSourceFiles: 'js/*.js',
    jsSourcePlugins: [
      'js/plugins/*.js',
      'js/plugins/helpers/*.js',
    ],
    jsResultFile: '../js/scripts.js',

    imgDir: '../img',
    imgBaseFiles: '<%= imgDir %>' + '/base64/*.{png,jpg,gif}',

    // Pagespeed options
    pageUrl: 'https://developers.google.com',
    pageThreshold: 70,
    pageDevice: 'desktop'
  });

  // Загрузка конфигурации к задачам из отдельных файлов
  grunt.loadTasks('tasks');

  // Задача по умолчанию
  grunt.registerTask('default', ['datauri', 'datauriMobile', 'compass', 'csslint', 'autoprefixer', 'cssmin', 'jshint', 'concat', 'uglify']);
  grunt.registerTask('dev',     ['compass', 'csslint', 'autoprefixer', 'jshint', 'concat']);
  grunt.registerTask('comb',    ['compass', 'csslint', 'autoprefixer', 'cssmin', 'csscomb']);
  grunt.registerTask('test',    ['dalek']);
  grunt.registerTask('speed',   ['pagespeed']);
};

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2017-08-17
@slo_nik

The issue was resolved by itself)))
I don’t know what I did, I deleted everything and pulled the design again and it all worked)))
Why it didn’t work remained a mystery)))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question