繁体   English   中英

Bower与Visual Studio Publish

[英]Bower with Visual Studio Publish

我想在Visual Studio 2015中开发的MVC 4应用程序中使用Bower。我知道当你有一个MVC 5项目时,使用Visual Studio 2015 Update 1,Bower管理有一个很好的用户界面,就像nuget界面一样。 这部分并不重要。

我目前正在使用bower - 我有npm和bower设置,我在解决方案中有package.json和bower.json文件。 保存时,Visual Studio会自动运行“npm install”,我在package.json中有一个postinstall步骤来运行“bower install”。

我不想将bower_components放入解决方案(或源代码控制)。 我想要的只是保留json配置文件,当你保存时,将检索所有依赖项。

这一切都可以在开发中正常工作,但是无效的是右键单击Web项目,发布。 发布不运行“npm install”,并且不包括解决方案中未包含的文件(除了它似乎与解决方案中未包含的nuget包一起使用)。 “发布Web”功能是我使用IIS部署将Web应用程序部署到生产环境的方式。

如何使Visual Studio Web Publish与Bower协同工作?

另一种选择 - 我已经看到Team System Builds有新的钩子可以运行gulp任务,但我不知道你可以用这种方式直接发布到IIS。

而不是引用/部署完整的bower_components文件夹,您可以使用gulp或grunt脚本(选择您喜欢的任何内容)将正确的文件从bower_components文件夹复制到类似scripts / lib的文件。

然后,您可以将这些文件包含在源代码管理中,然后进行部署。

以下是我用来完成此任务的grunt文件:

module.exports = function (grunt) {
    grunt.initConfig({
        pkg: grunt.file.readJSON("package.json"),
        copy: {
            main: {
                files: [
                  {
                      expand: true,
                      flatten: true,
                      src: [
                          'node_modules/vss-sdk/lib/VSS.SDK.js',
                          'node_modules/moment/moment.js',
                          'node_modules/moment-timezone/moment-timezone.js',
                          'node_modules/jquery/dist/jquery.js',
                          'bower_components/datetimepicker/jquery.datetimepicker.js',
                          'bower_components/datetimepicker/jquery.datetimepicker.css',
                      ],
                      dest: 'scripts/lib',
                      filter: 'isFile'
                  }              
                ]
            }
        }
    });

    grunt.loadNpmTasks("grunt-exec");
    grunt.loadNpmTasks("grunt-contrib-copy");
};

在ASP.NET Core(即MVC6)中,Bower被配置(在.bowerrc文件中)以将脚本添加到wwwroot / lib而不是bower_components文件夹。 该内容确实由Visual Studio发布。

使用.a bowerrc文件的相同方法适用于MVC4网站(至少如果您使用的是Visual Studio 2015)。 但是,它也会被检入版本控制,因此它可能不是您想要的。

.bowerrc文件可用于执行各种操作(请参阅http://bower.io/docs/config/ )。 但是,要让Bower在〜/ scripts / lib中向项目添加脚本,只需添加以下json:

{
  "directory": "scripts/lib"
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM