Symfony Webpack-使用子目录中的自定义字体



我在使用自定义字体文件编译sass文件时遇到问题。

这就是我的目录结构:

app.scss文件内容:

@import '../../../libraries/SymfonyBundle/assets/css/helper';

helper.scss文件内容:

@import "helpers/grid";
@import "helpers/colors";
@import "helpers/fonts";

fonts.scss文件内容:

@font-face {
font-family: "custom-font";
src: url("../../fonts/custom-font.eot");
font-weight: normal;
font-style: normal;
}

自定义捆绑文件位置:

/var/www/libraries/SymfonyBundle/assets/font/custom-font.eot

/var/www/libraries/SymfonyBundle/assets/css/helper.scss

/var/www/libraries/SymfonyBundle/assets/css/helpers/fonts.scss

我应该提供什么网址?我试过../../../../libraries/SymfonyBundle/assets/fonts/custom-font.eot(相对于网站构建目录(、../../fonts/custom-font.eot(相对于库scss文件(。

但我在运行yarn run encore dev命令时仍然收到这个错误:

未找到此相关模块:

*../../..//libraries/SymfonyBundle/assets/font/customerfont.eot/node_modules/css加载器??裁判4-2/node_modules/sas-loader/lib/loader.js??裁判4-3/assets/css/app.scs`

webpack.config.js

var Encore = require('@symfony/webpack-encore');
Encore
// the project directory where compiled assets will be stored
.setOutputPath('public/build/')
// the public path used by the web server to access the previous 
directory
.setPublicPath('/build')
.cleanupOutputBeforeBuild()
.enableSourceMaps(!Encore.isProduction())
// uncomment to create hashed filenames (e.g. app.abc123.css)
.enableVersioning(Encore.isProduction())
// uncomment to define the assets of the project
.addEntry('js/app', './assets/js/app.js')
.addStyleEntry('css/app', './assets/css/app.scss')
// uncomment if you use Sass/SCSS files
.enableSassLoader(function(sassOptions) {}, {
resolveUrlLoader: false
})
// uncomment for legacy applications that require $/jQuery as a global 
variable
.autoProvidejQuery()
;
module.exports = Encore.getWebpackConfig();

无论何时运行Encore,都会在outputPath目录中自动创建一个manifest.json文件。请检查此文件中的路径。特别是斜线:和setOutputPath:的值/build/vs/buld vs build。

如果你的Symfony住在小区(比如http://dev.local/my-symfony-app/)也是。参见:Symfony官方常见问题中的这一段

最新更新