简体   繁体   中英

Installing jQuery-Mobile via bower

In my project I would like to use jquery-mobile via bower.

Before I can use it I have to run npm install and grunt subsequently inside of bower_components/jquery-mobile before I can use the minified .js and .css files.

This is quite tedious and if I had to do this for every library that I use, I guess I would fallback to just downlading the files and add them to my project.

So is there a more elegant way to get to those "final" files via bower dependency?

My bower.json

"dependencies": {
    ...     
    "jquery-mobile": "latest",
}

The fact of having to run npm/grunt process (or not) is up to each author. In the case of jQuery Mobile, probably some external user has registered it without noticing that it needs to run Grunt tasks; Bower unfortunately allows everyone to register packages (is that bad or good? :S).

Also, there may exist some Grunt task to install bower dependencies and run their Grunt tasks aswell; if there aren't, it's not too complicated to create one.

Anyway, as it seems that you're in a "hurry" for those final, compiled files, there is jquery-mobile-bower , which has been created and registered into Bower a few hours ago.

bower install jquery-mobile-bower

Let's just hope that this gets maintained and up-to-date.

Just so you're aware, there is an official jQuery mobile Bower package available. It can be installed via:

bower install jquery-mobile

Its GitHub endpoint can be found here .

I'm not sure if my solution is optimal, but I removed jquery-mobile from bower.json and I'm installing and building it with Grunt , using grunt-contrib-clean , grunt-git and grunt-run plugins. I came up with this, because I don't want to use jquery-mobile-bower , because it's an unofficial repo.

Here's an example Gruntfile.js :

module.exports = function (grunt) {

    grunt.initConfig({
        clean: {
            jquerymobile: 'bower_components/jquery-mobile'
        },
        gitclone: {
            jquerymobile: {
                options: {
                    repository: 'https://github.com/jquery/jquery-mobile.git',
                    branch: 'master',
                    directory: 'bower_components/jquery-mobile'
                }
            }
        },
        run: {
            options: {
                cwd: "bower_components/jquery-mobile"
            },
            jquerymobile_npm_install: {
                cmd: "npm",
                args: [
                    'install'
                ]
            },
            jquerymobile_grunt: {
                cmd: "grunt"
            }
        }
    });

    grunt.loadNpmTasks('grunt-contrib-clean');
    grunt.loadNpmTasks('grunt-git');
    grunt.loadNpmTasks('grunt-run');

    grunt.registerTask('default', [
        'clean',
        'gitclone',
        'run'
    ]);
};

More details can be found here https://github.com/jquery/jquery-mobile/issues/7554

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