我有使用自定义字体文件编译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/custom-font.eot in ./node_modules/css-loader??ref--4-2 !./ node_modules /上海社会科学院装载机/ lib目录/ loader.js ??裁判 - !4-3 ./资产/ CSS / app.scss`
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();
1 回答
无论何时运行Encore,都会在outputPath目录中自动创建manifest.json文件 . 检查此文件中的路径 . 特别是斜杠:和setOutputPath的值:./ build / vs / buld vs build .
如果您的Symfony也存在于子目录(如http://dev.local/my-symfony-app/)中,那可能会很棘手 . 见:Symfony official FAQ中的这一段