简体   繁体   中英

Grunt - plugin folder disapper after build dist

I'm new to Yeoman, Grunt and Bower and of course I have some trouble when building a distribution.

I used Yeoman to scaffold a webapp, built the code, added an external plugin (not through bower, there was no package for that plugin, so I just copied the plugin folder and added the references in my index.html)

When running grunt serve everything works fine, the first time I built the distribution with

grunt

I had back a lot of jshint errors about that external plugin (missing semicolons etc...small things), so I just had to run

grunt --force

to have my dist built.

In the dist folder, the external plugin folder and files were missing, so in the build process that folder was removed (but the index.html file had all the references to the files).

So with

grunt serve:dist

I had my dist on the browser, but without the plugin. At this point I copied the plugin folder in the correct spot of the dist folder, reloaded the page, and the plugin was working. Then killed the process, and I run again

grunt serve:dist

After this command, the plugin folder (that I manually copied) just disappeared, so I realize that the copy and paste is not the right way to make things working.

How can I tell grunt (or bower) to leave that folder (inside the js folder) in the same spot, not try to compress the files inside, ignore js validation with jshint, and not to remove it?

What if I want to add a new folder (called for example jsons) in the root folder? When building a distribution will be removed too? Is there a spot where I can tell grunt what folder to include/ignore?

Thanks

---- EDIT ----

This is my "copy" task in Gruntfile.js

copy: {
  dist: {
    files: [{
      expand: true,
      dot: true,
      cwd: '<%= config.app %>',
      dest: '<%= config.dist %>',
      src: [
        '*.{ico,png,txt}',
        'images/{,*/}*.webp',
        '{,*/}*.html',
        'styles/fonts/{,*/}*.*'
      ]
    }, {
      src: 'node_modules/apache-server-configs/dist/.htaccess',
      dest: '<%= config.dist %>/.htaccess'
    }]
  },
  styles: {
    expand: true,
    dot: true,
    cwd: '<%= config.app %>/styles',
    dest: '.tmp/styles/',
    src: '{,*/}*.css'
  }
}

This in an extract of a 'production' Gruntfile.js :

module.exports = function (grunt) {

  copy: {
    dist: {
      files: [{
        expand: true,
        dot: true,
        cwd: '<%= yeoman.app %>',
        dest: '<%= yeoman.dist %>',
        src: [
          //'*.{ico,png,txt}',
          '*.{txt}',
          '.htaccess',
          '*.html',
          '*.appcache',
          'views/{,*/}*.html',
          'images/{,*/}*.{webp}',
          'icons/**/*.{ico,png}',
          'scripts/i18n/{,*/}*.js',
          'i18n/{,*/}*.json',
        ]
      }, {
        expand: true,
        cwd: '.tmp/images',
        dest: '<%= yeoman.dist %>/images',
        src: ['generated/*']
      }, {
        expand: true,
        cwd: 'bower_components/bootstrap/dist',
        src: 'fonts/*',
        dest: '<%= yeoman.dist %>'
      }, {
        expand: true,
        cwd: 'bower_components/open-sans-fontface',
        src: 'fonts/**/*',
        dest: '<%= yeoman.dist %>/styles'
      }, {
        expand: true,
        cwd: 'bower_components/font-awesome',
        src: 'fonts/*',
        dest: '<%= yeoman.dist %>'
      }]
    },
  },

  ...

  grunt.registerTask('build', [
    'clean:dist',
    ...
    'copy:dist',
    ...
  ]);

  grunt.registerTask('default', [
    'build',
  ]);

};

Please , read http://gruntjs.com/getting-started (it's a five minutes task... :-).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM