Cordova 将 www 文件夹复制到现有版本
Cordova copy www folder to existing build
如果我们只更改了 cordova 项目 www/
文件夹中的资产,并且没有更改任何原生 code/plugins,难道不应该有一个脚本只将新的 www/
文件夹替换为 ios 构建输出中的现有文件夹?
这样我们就不必每次想在模拟器中进行小改动并重新运行时都使用cordova build ios
重新构建整个ios项目.这将每天为我们节省大量时间。
是否已经存在这样的东西?
您可以通过三种方式存档:
为从根 www 文件夹到平台 www 文件夹的每个文件或文件夹创建绝对符号链接。但不要符号链接整个 www 文件夹,也不要符号链接 cordova.js 文件。
在 Xcode -> Build Phases 中,您可以将 copy-shell-scripts 放在 Copy www 目录中,用于 www 文件夹中的每个文件或文件夹。它应该看起来像:
cp -R /absolute/path/to/your/app/www/index.html /absolute/path/to/your/app/platforms/ios/www/index.html
你可以使用挂钩。把下面的钩子放在 hooks->after_platform_add->create_symlinks.js 和 hooks->after_build->create_symlinks.js 中。每次添加 android 或 ios 平台或构建应用程序时,挂钩都会 运行.
您必须使脚本可执行,也许您需要从 npm 安装 shelljs。
这是我的钩子,根据您的需要修改它:
#!/usr/bin/env node
var what_to_symlink_from_www = [
"assets",
"index.html"
];
// no need to change below
var path = require("path"),
fs = require("fs"),
shell = require("shelljs"),
rootdir = process.argv[2],
added_platform = process.env.CORDOVA_PLATFORMS,
www = rootdir + "/www/",
android_www = rootdir + "/platforms/android/assets/www/",
ios_www = rootdir + "/platforms/ios/www/",
buildnumber_file = rootdir + "/buildnumber",
buildnumber,
active_platform_www;
shell.echo("\r\nHook start: Symlinking");
if (added_platform === "ios") {
active_platform_www = ios_www;
do_job()
}
else if (added_platform === "android") {
active_platform_www = android_www;
do_job()
}
function do_job() {
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");
}
你可以 运行
cordova prepare
https://cordova.apache.org/docs/en/latest/reference/cordova-cli/#www
如果我们只更改了 cordova 项目 www/
文件夹中的资产,并且没有更改任何原生 code/plugins,难道不应该有一个脚本只将新的 www/
文件夹替换为 ios 构建输出中的现有文件夹?
这样我们就不必每次想在模拟器中进行小改动并重新运行时都使用cordova build ios
重新构建整个ios项目.这将每天为我们节省大量时间。
是否已经存在这样的东西?
您可以通过三种方式存档:
为从根 www 文件夹到平台 www 文件夹的每个文件或文件夹创建绝对符号链接。但不要符号链接整个 www 文件夹,也不要符号链接 cordova.js 文件。
在 Xcode -> Build Phases 中,您可以将 copy-shell-scripts 放在 Copy www 目录中,用于 www 文件夹中的每个文件或文件夹。它应该看起来像: cp -R /absolute/path/to/your/app/www/index.html /absolute/path/to/your/app/platforms/ios/www/index.html
你可以使用挂钩。把下面的钩子放在 hooks->after_platform_add->create_symlinks.js 和 hooks->after_build->create_symlinks.js 中。每次添加 android 或 ios 平台或构建应用程序时,挂钩都会 运行.
您必须使脚本可执行,也许您需要从 npm 安装 shelljs。
这是我的钩子,根据您的需要修改它:
#!/usr/bin/env node
var what_to_symlink_from_www = [
"assets",
"index.html"
];
// no need to change below
var path = require("path"),
fs = require("fs"),
shell = require("shelljs"),
rootdir = process.argv[2],
added_platform = process.env.CORDOVA_PLATFORMS,
www = rootdir + "/www/",
android_www = rootdir + "/platforms/android/assets/www/",
ios_www = rootdir + "/platforms/ios/www/",
buildnumber_file = rootdir + "/buildnumber",
buildnumber,
active_platform_www;
shell.echo("\r\nHook start: Symlinking");
if (added_platform === "ios") {
active_platform_www = ios_www;
do_job()
}
else if (added_platform === "android") {
active_platform_www = android_www;
do_job()
}
function do_job() {
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");
}
你可以 运行
cordova prepare
https://cordova.apache.org/docs/en/latest/reference/cordova-cli/#www