Installing jQuery-Mobile via bower

百般思念 提交于 2019-12-08 14:57:58

问题


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",
}

回答1:


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.




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/17727787/installing-jquery-mobile-via-bower

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!