【问题标题】:babel with express js :avoid relative path importsbabel 与 express js:避免相对路径导入
【发布时间】:2018-08-26 08:32:42
【问题描述】:

目前我的进口是这样的

 import router from '../../app/routes'

有什么办法可以避免这种../../ 例如:import router from 'app/routes' in typescript 我可以这样做

{
  "@app/*":["app/*"]
}

Babel 中是否有相同的功能?

【问题讨论】:

    标签: javascript node.js express ecmascript-6 babeljs


    【解决方案1】:

    是的,你可以使用babel-plugin-module-resolver

    "plugins": [
      ["module-resolver", {
        "root": ["./src"],
        "alias": {
          "app": "./app",
        },
      }]
    ]
    

    例如,将对“app”的所有引用别名为./src/app

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-12
      • 2019-07-24
      • 1970-01-01
      • 2017-05-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多