使用GruntJS来过滤哪些文件被部署 [英] Using GruntJS to filter which files get deployed

查看:172
本文介绍了使用GruntJS来过滤哪些文件被部署的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我们使用的静态资源是Visual Studio中的Web项目的一部分。项目中有一些我们希望在本地想要部署到生产中的文件。我们通过使用.csproj文件来管理这个文件,并查看文件是否被标记为内容或无等(如果它被标记为无,则不会被部署)。



这是非常好的,但我们正在将我们的开发从Visual Studio中移植到更友好的IDE中。但是,如果我们添加或删除文件,我们仍然需要返回到Visual Studio并更新.csproj文件,以确保生产不会失去同步,并且构建不会中断。



这让我想起了,因为我们正在实施Node / Grunt,如果有一个插件可以处理类似的事情 - 白名单/黑名单服务器可以查看并决定要接收哪些文件以及哪些文件要离开的方法。



我已经尝试过谷歌搜索,但我没有太多的运气弄清楚如何短语,我希望有人在这里可以做到这一点。我也愿意听任何其他更好的方法来解决这个问题。

解决方案

Grunt自带的内置文件过滤器。你可以过滤任何东西,它非常强大。我不能提供具体的解决方案,而不必看到您的Grunt任务,但这里是一个不同的排除模式与 grunt-copy 任务的示例:

  copy:{
dist:{
files:[{
expand:true,
dot:true ,
dest:'dist',
src:[
'*。{ico,png,txt}',
'bower_components / ** / *',
'assets / images / {,* /} *。{webp}',
'assets / fonts / ** / *',
'index.html',
'!* .something',//排除所有扩展名为.something的文件
'!.tmp / ** / *'//递归地排除.tmp目录下的所有文件
]
}]
}

Grunt使用 node-glob ,因此您可能需要浏览有关不同模式的文档。



我也将提到有一些插件在任何文件上形成字符串替换(例如咕噜替换)。使用这样的东西,您可以自动修改您的 .csproj 文件,以根据您的Grunt过滤器添加/删除文件(反之亦然)。请原谅轶事,但是作为一个前.NET开发人员,他依靠Visual Studio来处理我的一切事情,我最初被复杂性吓倒了, Node.js进程明显虚弱。我对你的信息不会被吓倒,一旦我变得舒服,我意识到我已经掌握了构建过程的各个方面,不再受到VS的怜悯。这是我职业生涯中解放最快的时刻,我没有回头看。


Currently the static resources we use are part of a web project in Visual Studio. There are certain files in the project that we want locally that we don't want being deployed to production. We manage this by using the .csproj file and seeing if a file is mark as "content" or "none" etc. (If it's marked as "none" it doesn't get pulled on the deploy).

This works great however we are moving our development out of Visual Studio and into a more Javascript friendly IDE. However if we add or delete files we still need to go back to Visual Studio and update the .csproj file to ensure that production won't get out of sync and that the build won't break.

This got me thinking, as we are implementing Node/Grunt if there's a plug-in of sorts that handles kind of the same thing -- a whitelist/blacklist kind of approach that the server could look at and decide which files to pick up and which ones to leave.

I've tried googling around but I'm not having much luck in figuring out exactly how to phrase it and I'm hoping someone here has any idea on how this can be done. I'm also willing to hear any other better ways of perhaps handling this issue. That in environment agnostic.

解决方案

Grunt comes with built-in file filters. You can filter anything, it's very powerful. I can't offer a specific solution without seeing your Grunt tasks, but here is an example of different exclusion patterns with the grunt-copy task:

copy: {
  dist: {
    files: [{
      expand: true,
      dot: true,
      dest: 'dist',
      src: [
        '*.{ico,png,txt}',
        'bower_components/**/*',
        'assets/images/{,*/}*.{webp}',
        'assets/fonts/**/*',
        'index.html',
        '!*.something',  // exclude all files with the extension .something
        '!.tmp/**/*'     // exclude all files recursively under .tmp directory
      ]
    }]
 }

Grunt uses node-glob so you may want to explore the documentation there to learn about different patterns.

I will also mention that there are plugins to perform string replacements on any file (eg. grunt-replace). With something like that, you can modify your .csproj file automatically to add/remove files based on your Grunt filters (or vice versa).

Please excuse the anecdote, but as a former .NET developer myself who relied on Visual Studio to handle everything for me, I was initially intimidated by the complexity and apparent frailty of Node.js processes. My message to you would be don't get intimidated, once I became comfortable I realized I had control over every aspect of the build process and was no longer at the mercy of VS. It was the most liberating moment of my career and I haven't looked back.

这篇关于使用GruntJS来过滤哪些文件被部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆