通过bower安装jQuery-Mobile

13

在我的项目中,我希望通过Bower使用jQuery Mobile。

在使用它之前,我必须在bower_components/jquery-mobile目录下依次运行npm installgrunt,然后才能使用压缩的.js.css文件。

这相当繁琐,如果我必须为每个库都这样做,我想我会退而求其次,只是下载文件并将它们添加到我的项目中。

那么,有没有更优雅的方法通过Bower依赖获取这些“最终”文件呢?

我的bower.json文件:

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

1
“bower install jquery-mobile-bower” 似乎是几个小时前创建的 :o - gustavohenke
事实上,我也刚刚偶然发现了这个。请随意将其添加为答案。当我成功测试后,我会接受它... - Besi
3个回答

19

每个作者决定是否运行npm/grunt进程。在jQuery Mobile的情况下,可能有些外部用户注册了它,却没有注意到它需要运行Grunt任务;不幸的是,Bower允许任何人注册包(这是好事还是坏事?:S)。

此外,可能存在一些Grunt任务来安装bower依赖项并运行它们的Grunt任务;如果不存在,则创建一个也不太复杂。

无论如何,因为您似乎对那些最终编译文件很“着急”,所以有jquery-mobile-bower,它已经在几小时前创建并注册到Bower中。

bower install jquery-mobile-bower

我们只希望这能够得到维护并保持最新。


7

需要提醒您的是,现在有一个官方的jQuery移动版Bower包可供使用。可以通过以下方式进行安装:

bower install jquery-mobile

jQuery Mobile的GitHub端点可以在这里找到。


2
这就是原始问题的内容。 - mcepl
@mcepl,我的回答提供了一个替代存储库,这似乎是官方的。谢谢。 - user1577333
1
原始问题是质疑为什么在这个 bower 仓库“jquery-mobile”中下载了开发文件。他们不想要 npm install && grunt。他们甚至在帖子中指定了使用 jquery-mobile。只是试图解释 @mcepl 的评论 :) 我在 bower install jquery-mobile 上遇到了很多麻烦。 - ProbablePrime

0

我不确定我的解决方案是否最优,但我从bower.json中删除了jquery-mobile,并使用Grunt安装和构建它,使用了grunt-contrib-cleangrunt-gitgrunt-run插件。我想到这个方法,是因为我不想使用jquery-mobile-bower,因为它是一个非官方的仓库。

这是一个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'
    ]);
};

更多细节可以在这里找到 https://github.com/jquery/jquery-mobile/issues/7554


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接