style-resources-loader icon indicating copy to clipboard operation
style-resources-loader copied to clipboard

import路径的计算似乎有些没有覆盖的场景

Open otakustay opened this issue 6 years ago • 1 comments

假设我们的结构是这样的:

/src <-- context
  /styles
    variables.less <-- pattern
  /components
    /FooBar
      /index.less <-- use
/node_modules
  /reset-less
    index.less

/src作为context,将/src/styles/variables.less作为被style-resources-loader处理的文件。在variables.less中写这样的代码:

@import "reset-less/index.less";

此时这个@import语句会被loader的逻辑修改为:../node_modules/reset-less/index.less

这导致在/src/components/FooBar/index.less中多出了@import "../node_modules/reset-less/index.less";这样一条语句,显然这是不可能找到正确的文件的

otakustay avatar Apr 18 '18 10:04 otakustay

这里可能有几个细节:

  1. 如何区分绝对的引用和相对的引用,这在less中和在js中并不相同,是不是干脆把路径交给webpack去resolve,而不要自己在文件系统上计算?
  2. less-loaderpaths配置,这个配置存在的情况下会取消webpack的路径查找功能,此处有可能存在一些兼容性问题

otakustay avatar Apr 18 '18 10:04 otakustay