css - 找不到 postcss 导入 iconfont .woff .ttf

标签 css filepath postcss

我通过 npm css 包导入了 iconfont.css,但是找不到 iconfont.woff 和 iconfont.tff。我该如何解决?

吞咽文件

var postcss = require('gulp-postcss');
var atImport = require('postcss-import');
var cssnano = require('cssnano');

gulp.task('importcss', function () {
    var processors = [
        atImport({}),
        cssnano()
    ];
    return gulp.src('./htdocs/css/common.css')
        .pipe(postcss(processors))
        .pipe(gulp.dest('./htdocs/css-build/'))
});

Npm Css 字体

enter image description here

css/common.css

enter image description here

css-build/common.css

enter image description here

页面

enter image description here

最佳答案

您需要使用 https://github.com/postcss/postcss-url在 postcss 导入之后。 postcss-url 将调整您的 URL 路径。

默认情况下,它会调整您的 URL 以引用 node_modules 中的原始文件。

如果您不在部署中包含 node_modules,它将无法工作。要解决此问题,请设置 url option复制。这会将所有 Assets 复制到 css-build/assets/ 并相应地调整 URL。

您还可以将 url 设置为 inline,这将对您的所有 Assets 进行 base64 编码并将其内联。除非您的 Assets 非常小,否则我不建议使用它。

关于css - 找不到 postcss 导入 iconfont .woff .ttf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39761187/

相关文章:

css - 如何使用 iframe 阻止列中的 div 进入另一列下方?

javascript - 如何使用 jQuery 在 firefox 中获取背景位置 y?

java - 获取正在执行的类的文件系统路径

c# - AppContext.BaseDirectory vs Assembly.GetEntryAssembly().发布应用程序后位置是否相同?

css - Webpack --watch 不会触发特定目录中的 CSS 文件

用于生成 Google Font css PostCSS 工件的 Bash 脚本?

html - npm run build 并观看非常慢

html - 将同一 div 中的两个元素放在彼此下方

css - 这是 Firefox 的错误吗?此输入 [type =""] 规则后的 CSS 根本未被读取

C# SoundPlayer 类未在指定路径找到文件