【发布时间】:2019-05-15 00:29:53
【问题描述】:
所以我正在做一个 symfony 4 项目,因为我别无选择,所以我正在使用 webpack encore。 在我的 css 中,我正在尝试使用通过 font-face 导入的字体。
所以我有:
assets/css/app.css:
...
@font-face
{
font-family: "myfont";
src: url('build/fonts/myfont.eot'); /* IE9 Compat Modes */
src: url('build/fonts/myfont.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('build/fonts/myfont.woff') format('woff'), /* Modern Browsers */
url('build/fonts/myfont.ttf') format('truetype'), /* Safari, Android, iOS */
url('build/fonts/myfont.svg#myfont') format('svg'); /* Legacy iOS */
}
...
我的字体在 assets/fonts/ 中
我尝试了不同的路径/方式并得到了不同的错误消息,当前是:
未找到这些相关模块:
- ./build/fonts/myfont.eot 在 ./node_modules/css-loader??ref--1-2!./assets/css/ app.css
- ./build/fonts/myfont.svg 在 ./node_modules/css-loader??ref--1-2!./assets/css/ app.css
- ./build/fonts/myfont.ttf 在 ./node_modules/css-loader??ref--1-2!./assets/css/ app.css
- ./build/fonts/myfont.woff 在 ./node_modules/css-loader??ref--1-2!./assets/css /app.css error 命令失败,退出代码为 2。
请注意,我想保持简单,而不是下载不需要的东西来做这么简单的事情。
所以我的问题是:官方/基本的方法是什么(字体中的哪个路径,如果需要,哪个配置)? 我搜索了几天,但没有发现任何工作或适用于我的案例,知道它应该超级简单,这尤其令人沮丧。
我的 webpack.config.js 是默认的,未修改:
var Encore = require('@symfony/webpack-encore');
Encore
// directory where compiled assets will be stored
.setOutputPath('public/build/')
// public path used by the web server to access the output path
.setPublicPath('/build')
// only needed for CDN's or sub-directory deploy
//.setManifestKeyPrefix('build/')
/*
* ENTRY CONFIG
*
* Add 1 entry for each "page" of your app
* (including one that's included on every page - e.g. "app")
*
* Each entry will result in one JavaScript file (e.g. app.js)
* and one CSS file (e.g. app.css) if you JavaScript imports CSS.
*/
.addEntry('app', './assets/js/app.js')
.addEntry('index', './assets/js/index.js')
//.addEntry('page2', './assets/js/page2.js')
/*
* FEATURE CONFIG
*
* Enable & configure other features below. For a full
* list of features, see:
* https://symfony.com/doc/current/frontend.html#adding-more-features
*/
.cleanupOutputBeforeBuild()
.enableBuildNotifications()
.enableSourceMaps(!Encore.isProduction())
// enables hashed filenames (e.g. app.abc123.css)
.enableVersioning(Encore.isProduction())
// enables Sass/SCSS support
//.enableSassLoader()
// uncomment if you use TypeScript
//.enableTypeScriptLoader()
// uncomment if you're having problems with a jQuery plugin
//.autoProvidejQuery()
;
module.exports = Encore.getWebpackConfig();
谢谢
【问题讨论】:
标签: javascript css symfony webpack fonts