所以代码很简单:
电话.json
{"SERVER":{
"requests":{
"one":"1"
}
} }
文件ts
import json = require('../static/电话.json');
console.log(json.SERVER);
生成的javascript是正确的,在运行node js服务器时,控制台会记录json.服务器应打印"{requests:{one:'1'}}".
The typescript compiler (commonjs) however, somehow does not particularly like this situation and throws: "Cannot find module '../static/电话.json'".
当然,我试着写了一封信.d、 ts文件,如下所示:
declare module '../static/电话.json'{
var exp:any;
export = exp;
}
这显然会抛出:"环境模块声明不能指定相对模块名".
我还try 了不同的变体,比如:
declare module '电话.json' {
import * as json from '/private/static/电话.json';
export = json;
}
然后要求:
import json = require('电话.json');
没有一个能正常工作,并且有自己的小编译器错误:)
我想用外置的.json文件,因为我使用commonjs serverside和amd clientside,我想要一个文件来加载常量.