简体   繁体   English

使goto定义可用于两个es6跨项目

[英]Making goto definition work with two es6 cross projects

I am working on an html5 game engine and - in parallel - I am working on game using this engine. 我正在使用html5游戏引擎,并且-并行-我正在使用该引擎进行游戏。

Both are written using ES6 and transpiled using webpack. 两者均使用ES6编写,并使用webpack进行转译。 Both the engine and the app are in their own directory, with their own package.json. 引擎和应用程序都位于各自的目录中,并具有各自的package.json。

I use webpack to build the engine, and then use npm link to add a link in global node_modules that points to the engine, then use npm link engine in the app's directory to point to engine development directory. 我使用webpack构建引擎,然后使用npm link在全局node_modules中添加指向引擎的npm link engine ,然后在应用程序目录中使用npm link engine指向引擎开发目录。

That's working fine, and using sourcemaps I can have debuggers and navigate inside both the engine and the app. 一切正常,使用sourcemaps,我可以拥有调试器,并在引擎和应用程序中导航。

In VSCode, I have a workspace (I am using the insider builds) with two directories: one is the engine, the other one is the app. 在VSCode中,我有一个包含两个目录的工作区(我正在使用内部人员构建):一个是引擎,另一个是应用程序。 When working on the engine, I can cmd+click on any method and this will open the correct file in the engine. 在使用引擎时,我可以Cmd +单击任何方法,这将在引擎中打开正确的文件。 The same goes for the app. 该应用程序也是如此。

But when I am working on a file inside the app directory that makes use of the engine, cmd+clicking on some method from the engine won't work. 但是,当我在使用引擎的应用程序目录中的文件上工作时,cmd +单击引擎中的某些方法将不起作用。 Is there a way to make it work properly? 有没有办法使其正常工作? I guess this is because the main property in the engine's package.js refers to the (transpiled) built main, and not the main (webpack) ES6 app entry point. 我猜这是因为引擎的package.js中的main属性是指(已编译的)内置main,而不是ES6应用程序的主要入口。 What could I do to make it work as expected? 我该怎么做才能使其按预期工作?

Actually this can be fixed using jsconfig.json configuration file that's used by the Typescript compiler of VSCode. 实际上,可以使用jsconfig.json的Typescript编译器使用的jsconfig.json配置文件解决此问题。

It can accept aliases that will then be used by the compiler instead of using the main entry of the package.json file. 它可以接受将由编译器使用的别名,而不是使用package.json文件的主条目。

For example, I used this: 例如,我使用了这个:

{
    "compilerOptions": {
        "target": "es2016",
        "module": "es6",
        "baseUrl": ".",
        "paths": {
            "athenajs": [
                "./node_modules/athenajs/js/athena-module"
            ]
        }
    }
}

See this cookbook for more information on jsconfig.json. 有关jsconfig.json的更多信息,请参见此食谱

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM