作者:张富春(ahfuzhang),转载时请注明作者和引用链接,谢谢!
先上代码:(在 macos 上调试通过)
# define a shell function to set debug mode to release mode
# when os is macbook, use gsed as sed
define function_sed_set_release_mod
set -x; \
sedcmd="sed"; \
if [[ "$$OSTYPE" == "darwin"* ]]; then \
sedcmd="gsed"; \
if [[ ! -f "/opt/homebrew/bin/gsed" ]]; then \
brew install gnu-sed; \
fi; \
fi; \
$$sedcmd -e 's/const\s\+_debug\s*=\s*\(true\|false\)\s*;\?/const _debug = false;/' $1 > $2;
endef
# 把 `const _debug = true;` 修改为 ``const _debug = false;``
release.js: debug.js
@$(call function_sed_set_release_mod, debug.js, release.js )
执行:make release.js
便可以实现用 sed 替换