Bower 与 Visual Studio 发布
Bower with Visual Studio Publish
我想在 Visual Studio 2015 年开发的 MVC 4 应用程序中使用 Bower。我知道当你有一个 MVC 5 项目时,Visual Studio 2015 更新 1,有一个很好的 UI 用于 Bower 管理,很像 nuget 界面。这部分并不重要。
我目前正在使用 Bower - 我有 npm 和 Bower 设置,并且我在解决方案中有 package.json 和 bower.json 文件。当您保存时,Visual Studio 自动 运行s "npm install" 并且我在 package.json 到 运行 "bower install".
中有一个安装后步骤
我不想将 bower_components 放入解决方案(或源代码管理)中。我想要的是只保留 json 配置文件,当你保存时,所有依赖项都会被检索。
这在开发中一切正常,但不起作用的是右键单击“Web 项目”,“发布”。发布不 运行 "npm install",也不包含解决方案中未包含的文件(除了它似乎以某种方式与解决方案中未包含的 nuget 包一起使用)。 "Publish Web" 功能是如何使用 IIS 部署将我的 Web 应用程序部署到生产中。
如何使 Visual Studio Web 发布与 Bower 一起工作?
另一种选择 - 我已经看到团队系统构建的新挂钩将 运行 gulp 任务,但我不知道您是否可以通过这种方式直接发布到 IIS。
而不是 referencing/deploying 完整的 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"
}
我想在 Visual Studio 2015 年开发的 MVC 4 应用程序中使用 Bower。我知道当你有一个 MVC 5 项目时,Visual Studio 2015 更新 1,有一个很好的 UI 用于 Bower 管理,很像 nuget 界面。这部分并不重要。
我目前正在使用 Bower - 我有 npm 和 Bower 设置,并且我在解决方案中有 package.json 和 bower.json 文件。当您保存时,Visual Studio 自动 运行s "npm install" 并且我在 package.json 到 运行 "bower install".
中有一个安装后步骤我不想将 bower_components 放入解决方案(或源代码管理)中。我想要的是只保留 json 配置文件,当你保存时,所有依赖项都会被检索。
这在开发中一切正常,但不起作用的是右键单击“Web 项目”,“发布”。发布不 运行 "npm install",也不包含解决方案中未包含的文件(除了它似乎以某种方式与解决方案中未包含的 nuget 包一起使用)。 "Publish Web" 功能是如何使用 IIS 部署将我的 Web 应用程序部署到生产中。
如何使 Visual Studio Web 发布与 Bower 一起工作?
另一种选择 - 我已经看到团队系统构建的新挂钩将 运行 gulp 任务,但我不知道您是否可以通过这种方式直接发布到 IIS。
而不是 referencing/deploying 完整的 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"
}