Storybook: 绝对路径的问题

创建于 2016-07-25  ·  3评论  ·  资料来源: storybookjs/storybook

这有效

import Component from '../component.jsx';

抛出错误

import Component from '/client/modules/account_details/components/component.jsx';

Module not found: Error: Cannot resolve 'file' or 'directory'

我的一些组件在 import 语句中具有绝对路径,这也打破了故事。 除了做../../../../等之外,还有其他解决方法吗?

我尝试使用https://github.com/mantrajs/babel-root-slash-import但开始得到
添加该包和.babelrc文件后Uncaught SyntaxError: Unexpected token import问题

{
  "plugins": [
    "babel-root-slash-import"
  ]
}

所有3条评论

能够解决这个问题

{
  "presets": ["es2015", "react"],
  "plugins": [
    "babel-root-slash-import"
  ]
}
{
    "presets": ["es2015", "react"],
    "plugins": [
        [
            "babel-root-slash-import", {
                "rootPathSuffix": "src/"
            }
        ]
    ]
  }

像这样的东西?
因为这不起作用

这也是从 create react app 覆盖 .babelrc 的默认配置吗?

此页面是否有帮助?
0 / 5 - 0 等级