How make bower build the package?

早过忘川 提交于 2019-12-03 16:04:43

问题


Is there a way to make bower run a package grunt after it was cloned from GitHub?

I'm trying to use Bower but one of the packages I'm using is the Bootstrap extension, x-editable. The problem is that while other packages push a fully built version to github so when installed by Bower you have a built version x-editable expect you to run a grunt file to build the package.

That is a common practice in other package managers like npm but I could find how to make Bower build it on install. Which means I need another mechanism to complete the installation of the package.


回答1:


Building on install is an anti-pattern and is strongly recommended against in Node. Like Node, Bower packages should be pre-built. This is because the end-user shouldn't have to care what preprocessor or build-system a package requires.

Your best options are to either convince the author to pre-build, fork and do it yourself, or build manually after you've installed the component.

The Bower team is planning to add the ability to publish packages to a server similar to how it works in npm. This will make it much better for packages needing a build-step.




回答2:


There are 3 hooks in bower, postinstall may solve your problem if for whatever reason you can not pre-built like @Sindre Sorhus points out.

In .bowerrc do:

{
    "scripts": {
        "preinstall": "<your command here>",
        "postinstall": "<your command here>",
        "preuninstall": "<your command here>"
    }
}

source https://github.com/bower/bower/blob/master/HOOKS.md




回答3:


You could use composer for handling post install:

bower.json:

{
    "dependencies": {
        "bootstrap": "*"
    }
}

composer.json:

{
    "scripts" : {
        "post-install-cmd" : [
            "bower install --no-color",
            "lessc bower_components/bootstrap/less/bootstrap.less public/script/bootstrap.css"
        ]
    }
}

Then I run composer install:

Loading composer repositories with package information
Installing dependencies (including require-dev)
Nothing to install or update
Generating autoload files
bower warn Package bootstrap is still using the deprecated "component.json" file
bower cloning git://github.com/twitter/bootstrap.git
bower cached git://github.com/twitter/bootstrap.git
bower fetching bootstrap
bower checking out bootstrap#v2.3.2
bower warn Package jquery is still using the deprecated "component.json" file
bower copying C:\Users\renadm\AppData\Roaming\bower\cache\bootstrap\9d49e0aedf207bebd028e26cc86a9e58
bower cloning git://github.com/components/jquery.git
bower cached git://github.com/components/jquery.git
bower fetching jquery
bower checking out jquery#1.8.3
bower copying C:\Users\renadm\AppData\Roaming\bower\cache\jquery\29cb4373d29144ca260ac7c3997f4381
bower installing bootstrap#2.3.2
bower installing jquery#1.8.3

After Bower finishes installing, the LESS compiler processes the .less files and puts a nice bootstrap.css in my public folder. something similar could be done for JavaScript files with Closure Compiler.



来源:https://stackoverflow.com/questions/17170500/how-make-bower-build-the-package

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