【问题标题】:How does import with tilde (~) work in parcel-2?使用波浪号 (~) 导入如何在 parcel-2 中工作?
【发布时间】:2020-10-15 22:00:27
【问题描述】:

在 parcel 1 中,我可以使用波浪号 (~) 导入,它通常指的是最近的目录或项目的根目录。但是,我最近升级到了 2 号地块,它在抱怨。如何在 typescript/react repo 中启用 ~ 路径解析器?我需要为此编写解析器还是有任何内置支持?这个设置有什么例子吗?

【问题讨论】:

标签: parcel parceljs


【解决方案1】:

尝试将其添加到您的 tsconfig.json

...
"baseUrl": "./src",
"paths": {
  "~/*": ["./*"]
},
...

【讨论】:

    【解决方案2】:

    在这里工作正常。 这是我的 package.json

    {
      "name": "my-pacakge",
      "version": "1.0.9-alpha",
      "description": "something",
      "scripts": {
        "start": "parcel index.html --open",
        "build": "parcel build --public-url . index.html",
        "pack": "npm-pack-zip"
      },
      "author": "",
      "license": "ISC",
      "dependencies": {},
      "devDependencies": {
        "bootstrap": "^5.0.2",
        "npm-pack-zip": "^1.2.9",
        "parcel": "^2.0.1"
      },
      "peerDependencies": {
        "@parcel/transformer-sass": "^2.0.1"
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-12-03
      • 2014-06-10
      • 2020-04-19
      • 1970-01-01
      • 2017-08-24
      • 2013-10-13
      • 2017-02-01
      相关资源
      最近更新 更多