Webpack&TypeScript:变量中的require(),带别名的大小写

时间:2018-07-22 04:56:53

标签: typescript webpack

我从变量中读取了一些有关要求的问题。这是我要考虑的别名情况。在下面的代码中,projectOpenScripts是别名。

export default class Resources {

  constructor(pathToResourcesFile: string){

    // true
    console.log(pathToResourcesFile === 'projectOpenScripts/resources/resources.json5') 

    // works
    let parsedResources = require('projectOpenScripts/resources/resources.json5'); 

    // does not work
    let parsedResources = require(pathToResourcesFile);
    console.log(parsedResources.c)
  }
}

tsconfig.json

{
  "compilerOptions": {

    // ...

    "baseUrl": "./",
      "projectOpenScripts": ["development/1_Source/1_open/3_scripts"]
    },

    "types": [
      // Need for require() and require.ensure
      "webpack-env"
    ]
  }
}

我不能接受我们不能要求变量-这种限制与编程概念相矛盾。除了正确获取resources.json5之外,我还需要禁止对TypeScript的警告Critical dependency: the request of a dependency is an expression

0 个答案:

没有答案