用nodejs读取了另一个js文件,得到该js文件的字符串,内容如下。
/*
* @Description: 生产环境
* @Author: [email protected]
*/
window.config = {
baseUrl: 'http://192.168.1.100',
describe: '生产环境'
};
如何获取到里面的对象内容,像下面这样。
{
baseUrl: 'http://192.168.1.100',
describe: '生产环境'
}
const str = `
/*
* @Description: 生产环境
* @Author: [email protected]
*/
window.config = {
baseUrl: 'http://192.168.1.100',
describe: '生产环境'
};
`
const re = /{[\S\s]*}/;
const match = str.match(re);
if(match){
eval('var obj =' + match[0])
console.log(obj)
}