将选项传递给流星上的JS编译器

发布于 2025-01-23 04:42:27 字数 397 浏览 5 评论 0原文

我们将jsconfig文件添加到流星项目的根部,以添加短双手形式导入。

例如,而不是从'../../ api/users/stutations'导入usermutations';我们想从'@api/users/stumations';

这是一个示例JSCONFIG文件

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@api/*": ["api/*"],
    }
  }
}

时,我们将其添加到npm backages时,我们的短手导入了丢失。

任何帮助都将受到赞赏

We are adding a jsconfig file to the root of a meteor project to add short hands form imports.

For instance instead of import UserMutations from '../../api/Users/mutations'; we would like to write import UserMutations from '@api/Users/mutations';

This is an example jsconfig file

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@api/*": ["api/*"],
    }
  }
}

When we add this our short hand imports recognized as npm packages that are missing.

Any help is appreciated

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

花开柳相依 2025-01-30 04:42:27

看起来您指的是
https://guide.meteor.com/build-tool.build-tool.htool.html.html#typescript 。因此,您的文件
需要称为tsconfig.json

Looks like what you are referring to is
https://guide.meteor.com/build-tool.html#typescript. Accordingly, your file
needs to be called tsconfig.json.

迷雾森÷林ヴ 2025-01-30 04:42:27

流星的构建系统在引擎盖下使用Babel。因此,您可以使用插件的“模块 - 溶液剂”来解决任务:

安装NPM软件包:

流星npm i babel-plugin-module-resolver

create .babelrc 在您的流星项目的根源:

{
  "plugins": [
    [
      "module-resolver",
      {
        "alias": {
          "@api": "./imports/api"
        }
      }
    ]
  ]
}

然后导入

imports
api
   users
      index.js
      utils.js
...
import { Users } from '@api/users';
import { SomeUtils } from '@api/users/utils.js';

Meteor's build system uses babel under the hood. So, you can solve your task with a plugin 'module-resolver':

Install npm package:

meteor npm i babel-plugin-module-resolver

Create .babelrc at the root of your meteor project:

{
  "plugins": [
    [
      "module-resolver",
      {
        "alias": {
          "@api": "./imports/api"
        }
      }
    ]
  ]
}

Then import

imports
api
   users
      index.js
      utils.js
...
import { Users } from '@api/users';
import { SomeUtils } from '@api/users/utils.js';
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文