Visual Studio Cordova 排除文件
Visual Studio Cordova exclude files
使用默认设置和空白 Typescript 项目,构建过程包括 apk/xap \www 目录中项目目录中的所有文件,包括 d.ts 和 .ts 文件。除了编辑 vs-mda 文件之外,是否有一种方法可以全局(不是 ant.properties 等)从打包中排除文件,同时保持智能感知并将 .ts 文件编译到正确的位置?
另一个方面是 ionic 和 angular nuget 包将 xxx.js 和 xxx.min.js 安装到 \scripts 目录中,最终都在 apk/xap 中。
我正在寻找一种可以在项目模板中正确使用的方法,以打包到 .vsix 模板分发中,而无需最终用户进行大量手动编辑。
不幸的是,在 VS2013 CTP3.1 中实现此目的的唯一方法是在自定义插件中创建 Cordova 挂钩。挂钩可以附加到 after_prepare 事件,然后您可以编写代码从 "bld" 下生成的 "platforms" 文件夹中的正确位置删除文件。
在此处查看 plugin-remove-typescript:https://github.com/Chuxel/taco-tricks
钩子移除-ts.js:
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 存储库中的 plugin-remove-typescript 文件夹中获取它并将其放入本地文件夹中。使用配置设计器的 "custom" 选项卡 select 它。您还可以通过更新插件中的 glob 语法来修改它以删除其他文件类型 (https://www.npmjs.com/package/glob)。
随着即将发布的 VS 2015,这种情况将得到改善。
有关 Cordova Hooks 的更多信息:http://cordova.apache.org/docs/en/dev/guide/appdev/hooks/index.html#Hooks%20Guide
好的,鉴于 Chuck Lantz 提供的框架,我编写了一个删除 .ts 和一些杂乱文件的插件。它还会在同一目录中存在缩小版本时删除未缩小的 js/css(如果需要,可以添加一个开关将其关闭)并提供一种机制来全局排除文件模式并在发布版本中按目录排除而不编辑插件。从 0.8.6 开始递归排除目录。
它在我正在开发的应用程序上减少了 75% ~5MB -> ~1MB。
https://github.com/MagicBoxSoftware/vs-cordova-3-1-ignore-files
@Chuck Lantz 几年前的回答确实帮助了我。
从那时起,科尔多瓦就发展起来了。
我尝试使用 cordova-plugin-exclude-files (Git, npm)。看起来不错,但是:
- 那毁了我的项目。
- 它使用after-prepare hook,在文件已经被复制后删除。
所以我放弃并编辑了 prepare.js (\v2\platforms\android\cordova\lib\prepare.js):
我更改了'updateWwwFrom'函数:
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);
}
}
添加辅助函数:
// 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-include.txt 文件。示例内容:
subdir/*
subdir2/file.png
使用默认设置和空白 Typescript 项目,构建过程包括 apk/xap \www 目录中项目目录中的所有文件,包括 d.ts 和 .ts 文件。除了编辑 vs-mda 文件之外,是否有一种方法可以全局(不是 ant.properties 等)从打包中排除文件,同时保持智能感知并将 .ts 文件编译到正确的位置?
另一个方面是 ionic 和 angular nuget 包将 xxx.js 和 xxx.min.js 安装到 \scripts 目录中,最终都在 apk/xap 中。
我正在寻找一种可以在项目模板中正确使用的方法,以打包到 .vsix 模板分发中,而无需最终用户进行大量手动编辑。
不幸的是,在 VS2013 CTP3.1 中实现此目的的唯一方法是在自定义插件中创建 Cordova 挂钩。挂钩可以附加到 after_prepare 事件,然后您可以编写代码从 "bld" 下生成的 "platforms" 文件夹中的正确位置删除文件。
在此处查看 plugin-remove-typescript:https://github.com/Chuxel/taco-tricks
钩子移除-ts.js:
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 存储库中的 plugin-remove-typescript 文件夹中获取它并将其放入本地文件夹中。使用配置设计器的 "custom" 选项卡 select 它。您还可以通过更新插件中的 glob 语法来修改它以删除其他文件类型 (https://www.npmjs.com/package/glob)。
随着即将发布的 VS 2015,这种情况将得到改善。
有关 Cordova Hooks 的更多信息:http://cordova.apache.org/docs/en/dev/guide/appdev/hooks/index.html#Hooks%20Guide
好的,鉴于 Chuck Lantz 提供的框架,我编写了一个删除 .ts 和一些杂乱文件的插件。它还会在同一目录中存在缩小版本时删除未缩小的 js/css(如果需要,可以添加一个开关将其关闭)并提供一种机制来全局排除文件模式并在发布版本中按目录排除而不编辑插件。从 0.8.6 开始递归排除目录。
它在我正在开发的应用程序上减少了 75% ~5MB -> ~1MB。
https://github.com/MagicBoxSoftware/vs-cordova-3-1-ignore-files
@Chuck Lantz 几年前的回答确实帮助了我。 从那时起,科尔多瓦就发展起来了。 我尝试使用 cordova-plugin-exclude-files (Git, npm)。看起来不错,但是:
- 那毁了我的项目。
- 它使用after-prepare hook,在文件已经被复制后删除。
所以我放弃并编辑了 prepare.js (\v2\platforms\android\cordova\lib\prepare.js):
我更改了'updateWwwFrom'函数:
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);
}
}
添加辅助函数:
// 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-include.txt 文件。示例内容:
subdir/*
subdir2/file.png