bod*_*ser 109 shell makefile environment-variables target
我想更改这个Makefile:
SHELL := /bin/bash
PATH := node_modules/.bin:$(PATH)
boot:
@supervisor \
--harmony \
--watch etc,lib \
--extensions js,json \
--no-restart-on error \
lib
test:
NODE_ENV=test mocha \
--harmony \
--reporter spec \
test
clean:
@rm -rf node_modules
.PHONY: test clean
Run Code Online (Sandbox Code Playgroud)
至:
SHELL := /bin/bash
PATH := node_modules/.bin:$(PATH)
boot:
@supervisor \
--harmony \
--watch etc,lib \
--extensions js,json \
--no-restart-on error \
lib
test: NODE_ENV=test
test:
mocha \
--harmony \
--reporter spec \
test
clean:
@rm -rf node_modules
.PHONY: test clean
Run Code Online (Sandbox Code Playgroud)
不幸的是,第二个不起作用(节点进程仍以默认值运行)NODE_ENV.
我错过了什么?
Mad*_*ist 137
默认情况下,Make变量不会导出到进程调用环境中.但是你可以使用make export来强制它们这样做.更改:
test: NODE_ENV = test
Run Code Online (Sandbox Code Playgroud)
对此:
test: export NODE_ENV = test
Run Code Online (Sandbox Code Playgroud)
(假设你有一个足够现代的GNU make版本).
Sha*_*Lee 54
正如MadScientist指出的那样,您可以使用以下方法导出单个变量:
export MY_VAR = foo # Available for all targets
Run Code Online (Sandbox Code Playgroud)
您也可以指定.EXPORT_ALL_VARIABLES目标 - 您猜对了! - 出口所有事情!!!:
my-target: export MY_VAR_1 = foo
my-target: export MY_VAR_2 = bar
my-target: export MY_VAR_3 = baz
my-target: dependency_1 dependency_2
echo do something
Run Code Online (Sandbox Code Playgroud)
Tho*_*ner 13
我只在本地需要环境变量来调用我的测试命令,这里是一个在bash shell中设置多个环境变量并转义美元符号的示例make.
SHELL := /bin/bash
.PHONY: test tests
test tests:
PATH=./node_modules/.bin/:$$PATH \
JSCOVERAGE=1 \
nodeunit tests/
Run Code Online (Sandbox Code Playgroud)