首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >排除文件

排除文件
EN

Stack Overflow用户
提问于 2015-04-16 19:25:22
回答 3查看 789关注 0票数 2

使用默认设置和空白类型记录项目,生成过程包括apk/xap \www dir中项目目录中的所有文件,包括d.ts和.ts文件。除了编辑vs文件之外,还有一种全局方法(不是ant.properties等)。在维护intellisense和将.ts文件编译到正确位置的同时,从打包中排除文件?

它的另一个方面是,离子和角nuget包将xxx.js和xxx.min.js安装到\scripts中,最后都在apk/xap中结束。

我正在寻找一种可以在项目模板中正确使用的方法,它可以打包到.vsix模板发行版中,而不需要最终用户进行大量手工编辑。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2015-04-17 16:27:54

不幸的是,在VS2013 CTP3.1中实现这一点的唯一方法是在自定义插件中创建一个Cordova钩子。钩子可以附加到after_prepare事件,然后您可以编写代码从生成的“平台”文件夹中"bld“下的正确位置删除文件。

参见插件-删除-类型记录这里:https://github.com/Chuxel/taco-tricks

钩子-删除-ts.js:

代码语言:javascript
运行
复制
module.exports = function (context) {

    var fs = require("fs");
    var glob = context.requireCordovaModule('glob');    

    context.opts.cordova.platforms.forEach(function(platform) {
        console.log("Processing " + platform);
        // Get all TS files under platforms folder
        glob("platforms/" + platform + "/**/*.ts", function(err, tsFiles) {
            if(err) throw err;
            tsFiles.forEach(function(tsFile) {
                console.log("Deleting " + tsFile);
                fs.unlinkSync(tsFile);
            });
        }); 
    });
}

要安装它,只需从Git中的插件-删除-类型记录文件夹抓取它,并将其放在本地文件夹中。使用配置设计器的“自定义”选项卡来选择它。您还可以通过更新插件(https://www.npmjs.com/package/glob)中的glob语法来修改它以删除其他文件类型。

随着即将发布的VS 2015版本,这种情况将得到改善。

关于科多瓦·胡克斯的更多信息:http://cordova.apache.org/docs/en/dev/guide/appdev/hooks/index.html#Hooks%20Guide

票数 4
EN

Stack Overflow用户

发布于 2015-04-19 20:19:44

好的,考虑到Chuck的框架,我编写了一个插件来删除.ts和一些杂乱的文件。它还删除在同一目录中存在一个小型化版本时不受限制的js/css (如果需要,可以添加一个开关来关闭该开关),并提供一种机制,在发布版本中根据每个目录排除文件模式和排除,而无需编辑插件。从0.8.6开始递归地排除目录。

在我正在开发的应用程序上,它减少了75% ~5MB的-> ~1MB。

https://github.com/MagicBoxSoftware/vs-cordova-3-1-ignore-files

票数 1
EN

Stack Overflow用户

发布于 2018-06-17 04:47:22

@查克·兰茨的回答几年前真的帮助了我。从那以后,科多瓦进化了。我试着使用科多瓦插件-排除-文件(Gitnpm)。看起来没问题,但:

  1. 毁了我的计划。
  2. 它使用后准备钩子,删除文件后,他们已经被复制.

所以我放弃并编辑了(\v2\platforms\android\cordova\lib\prepare.js):prepare.js

我更改了“updateWwwFrom”函数:

代码语言:javascript
运行
复制
function updateWwwFrom(cordovaProject, destinations) {
    // use per OS EOL symbol
    var endOfLine = require('os').EOL;
    // build whitelist file path
    var includeFile = path.join(cordovaProject.root, 'build-include.txt');
    // verbosing (will appear in Visual Studio output pane)
    events.emit('verbose', 'Copying files listed in ' + includeFile );
    // read the whitelist file
    var files = require('fs').readFileSync(includeFile, 'utf-8').split(endOfLine);
    // ORIGINAL // clear destination www dir
    shell.rm('-rf', destinations.www);
    // ORIGINAL // create destination www dir
    shell.mkdir('-p', destinations.www);

    // ORIGINAL // Copy source files from project's www directory
    // ORIGINAL shell.cp('-rf', path.join(cordovaProject.locations.www, '*'), destinations.www);

    // copy files from whitelist
    files.forEach( item => copyToWWW( path.join(cordovaProject.locations.www, item) , destinations.www,  path.dirname(item)));

    // ORIGINAL // Override www sources by files in 'platform_www' directory
    shell.cp('-rf', path.join(destinations.platformWww, '*'), destinations.www);

    // ORIGINAL // If project contains 'merges' for our platform, use them as another overrides
    var merges_path = path.join(cordovaProject.root, 'merges', 'android');
    if (fs.existsSync(merges_path)) {
        events.emit('verbose', 'Found "merges" for android platform. Copying over existing "www" files.');
        var overrides = path.join(merges_path, '*');
        shell.cp('-rf', overrides, destinations.www);
    }
}

新增辅助功能:

代码语言:javascript
运行
复制
// copy files from whitelist
function copyToWWW(source, dest, dirname)
{
    var destWithDirName = path.join(dest, dirname);
    shell.mkdir('-p', destWithDirName);
    shell.cp('-rf', source, destWithDirName );
}

并在我的项目根目录中创建了build de.txt文件。样本内容:

代码语言:javascript
运行
复制
subdir/*
subdir2/file.png
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29684190

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档