javascript 通过 bower 安装 jQuery-Mobile

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17727787/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 09:23:13  来源:igfitidea点击:

Installing jQuery-Mobile via bower

javascripthtmlnode.jsgruntjsbower

提问by Besi

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

在我的项目中,我想通过 bower 使用 jquery-mobile。

Before I can use it I have to run npm installand gruntsubsequently inside of bower_components/jquery-mobilebefore I can use the minified .jsand .cssfiles.

之前,我可以用它我要运行npm installgrunt内部随后bower_components/jquery-mobile我才可以使用精缩.js.css文件。

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?

那么有没有更优雅的方式通过 bower 依赖来获取那些“最终”文件?

My bower.json

我的 bower.json

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

回答by gustavohenke

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).

是否必须运行 npm/grunt 进程(或不运行)取决于每个作者。以 jQuery Mobile 为例,可能是一些外部用户注册了它,而没有注意到它需要运行 Grunt 任务;不幸的是,Bower 允许每个人注册软件包(是好是坏?:S)。

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

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

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 的jquery-mobile-bower

bower install jquery-mobile-bower

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

让我们只希望它得到维护和更新。

回答by Drew

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

请注意,有一个官方的 jQuery 移动 Bower 包可用。它可以通过以下方式安装:

bower install jquery-mobile

Its GitHub endpoint can be found here.

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

回答by Thomas Szteliga

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

我不知道如果我的解决方案是最佳的,但我删除jquery-mobilebower.json和我安装,并构建它Grunt,使用grunt-contrib-cleangrunt-gitgrunt-run插件。我想出了这个,因为我不想使用jquery-mobile-bower,因为它是一个非官方的回购。

Here's an example Gruntfile.js:

这是一个例子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://github.com/jquery/jquery-mobile/issues/7554