Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在执行此操作时排除文件复制到目标ios和android平台-cordova 6_Cordova_Ionic Framework_Phonegap Build - Fatal编程技术网

如何在执行此操作时排除文件复制到目标ios和android平台-cordova 6

如何在执行此操作时排除文件复制到目标ios和android平台-cordova 6,cordova,ionic-framework,phonegap-build,Cordova,Ionic Framework,Phonegap Build,我正在开发一款混合应用程序,带有角度材质设计和cordova。该应用程序运行得很好,我即将发货到商店 我在做什么时注意到了什么 cordova准备 cordova build没有禁止将所有www/*文件复制到正在创建的最终包的选项,但是,由于您已经有Grunt来构建资产,您可以创建额外的任务来从构建中删除这些文件 例如,使用该软件包,您将获得如下内容: Android del([path.join('platforms/android/assets/www', '/js/app')]); i

我正在开发一款混合应用程序,带有角度材质设计和cordova。该应用程序运行得很好,我即将发货到商店

我在做什么时注意到了什么

cordova准备

cordova build
没有禁止将所有www/*文件复制到正在创建的最终包的选项,但是,由于您已经有Grunt来构建资产,您可以创建额外的任务来从构建中删除这些文件

例如,使用该软件包,您将获得如下内容:

Android

del([path.join('platforms/android/assets/www', '/js/app')]);
iOS

del([path.join('platforms/ios/www', '/js/app')]);

然后您可以通过(after_prepare)调用这些任务。

在cordova进程之前或之后处理事情的最佳方法是使用挂钩。操作简单,非常灵活,请参见文档:

这是我使用的一个符号链接钩子,这一个应该可以解决您的问题,只需根据您的需要修改从www到www的符号链接即可:

module.exports = function (context) {

    var what_to_symlink_from_www = [
        "assets",
        "index.html",
    ];

    // Don't change things below this line

    var shell = require("shelljs"),
        rootdir = context.opts.projectRoot,
        platforms = context.opts.cordova.platforms,
        www = rootdir + "/www/";

    shell.echo("\r\nHook start: Symlinking");

    platforms.forEach(function (platform) {
        var active_platform_www;
        if (platform === "ios") {
            active_platform_www = rootdir + "/platforms/ios/www/";
        } else if (platform === "android") {
            active_platform_www = rootdir + "/platforms/android/assets/www/";
        } else {
            return;
        }

        what_to_symlink_from_www.forEach(function (item) {
            shell.rm("-rf", active_platform_www + item);
            shell.ln("-s", www + item, active_platform_www + item);
            shell.echo("symlinked: " + item + " to " + active_platform_www);
        });
    });

    shell.echo("Hook end: Symlinking\r\n");
};

我已经为此创建了一个grunt任务:

grunt.initConfig({
执行官:{
船舶:{
cmd:function(){
var命令=[];
var ios=“$PWD/platforms/ios/www/js”
var android=“$PWD/platforms/android/assets/www/js”
var paths=['app','config','directives','filter','lib','services',]
var平台=[android、ios]
对于(var i=0;i对于(var j=0;j所有以前的答案都不推荐

请注意,最新版本的爱奥尼亚(3.9.2)不再支持Cordova挂钩

(钩子将运行,但构建不会完成。)


帮你自己一个忙,节省你自己几个小时的时间(就像我做不到的),然后直接使用。

@Sensei James建议使用cordova插件排除文件。它看起来不错,但是:

  • 那毁了我的计划
  • 它使用after prepare钩子,在文件被复制后删除它们
  • 所以我放弃并编辑了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 );
    }
    
    新增辅助功能:

    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