我在将手写笔.styl文件编译为css时遇到了一个问题。如果手写笔文件包含@import,那么我就会遇到“找不到@import文件”错误。例如,我有两个简单的手写笔文件:
root
  - specific
     - particularButton.styl
  - button.styl
// --- button.styl ---
.button
  // some styles
// --- specific/particularButton.styl ---
@import "../button.styl"
.particular-button
    // some styles我试图通过使用以下代码将它们转换为css:
const stylus = require('stylus');
const fs = require('fs');
const filePath = // path to particularButton.styl
stylus(fs.readFileSync(filePath, 'utf8'))
    .set('paths', [
        // path to a folder that contain "button.styl"
    ])
    .render(function(err, css) {
        console.log(err);
        // <some action like> fs.writeFileSync(cssFileName, css);
    })根据手写笔API,我试图让它与.set('path' ...一起工作,而不需要这个设置。但没有成功。
有人能帮忙吗?
P.S.环境: OSX Mohave,节点: 6.9.1,npm: 6.4.1,手写笔: 0.54.5
Upd
问题在@import "../button.styl"的相对路径上。如果我用一条通向button.styl的绝对路径来替换它,它就会变成工作。但这似乎是个很糟糕的解决方案..。
发布于 2018-12-16 16:30:23
好吧,我刚发现。
我的问题是,我试图在.set()方法中添加错误的路径。可能是有一点不清楚的记录,伊克。
在particularButton.styl中出现相对导入的情况下,需要添加该文件本身的路径。不是导入文件。所以应该是:
stylus(fs.readFileSync(filePath, 'utf8'))
    .set('paths', [
        // path to a folder that contain "particularButton.styl"
    ])https://stackoverflow.com/questions/53803710
复制相似问题