Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/396.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将字体与网页重新编码一起使用_Javascript_Css_Symfony_Webpack_Fonts - Fatal编程技术网

Javascript 将字体与网页重新编码一起使用

Javascript 将字体与网页重新编码一起使用,javascript,css,symfony,webpack,fonts,Javascript,Css,Symfony,Webpack,Fonts,所以我正在做一个symfony4项目,因为我没有选择,所以我使用了网页安可。 在我的css中,我尝试使用一种字体,用字体导入 因此,我: 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(

所以我正在做一个symfony4项目,因为我没有选择,所以我使用了网页安可。 在我的css中,我尝试使用一种字体,用字体导入

因此,我:

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 */
}
...
我的字体在资源/字体中/

我尝试了不同的路径/方法,得到了不同的错误消息,当前的错误消息是:

未找到这些相关模块:

  • ./build/fonts/myfont.eot in./node_modules/css loader??ref--1-2/资产/css/ app.css
  • ./build/fonts/myfont.svg in./node_modules/css loader??ref--1-2/资产/css/ app.css
  • ./build/fonts/myfont.ttf in./node_modules/css loader??ref--1-2/资产/css/ app.css
  • ./build/fonts/myfont.woff in./node_模块/css加载器??参考-1-2/资产/css /app.css 错误命令失败,退出代码为2
请注意,我想让它保持简单,而不是下载一些不需要做这么简单的事情的东西

所以我的问题是:官方/基本的方法是什么(字体中的哪个路径,以及需要的配置)? 我搜索了几天,但没有发现任何有效或适用于我的案例,知道这应该是非常容易的,这尤其令人沮丧

My 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();

谢谢

我放弃了在没有插件或加载程序的情况下使用它,我尝试了文件加载程序:不起作用,我尝试了复制插件:成功

webpack.config.js

var Encore = require('@symfony/webpack-encore');

var CopyWebpackPlugin = require('copy-webpack-plugin');

Encore
    ...
    .addPlugin(new CopyWebpackPlugin([
        { from: './assets/fonts', to: 'fonts' }
    ]))
    /*.addLoader({
        test: /\.(eot|svg|ttf|woff)$/,
        use: [{
            loader: 'file-loader',
            options: {
                name: '[path][name].[ext]',
                context: './assets',
            }
        }]
    })*/

    ...
;

module.exports = Encore.getWebpackConfig();
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 */
}

另一种方法是更改字体文件的保存方式。 你可以在这里读更多

Encore
    .addLoader({
        test: /\.(woff|woff2|eot|ttf|otf)$/,
        use: [
            {
                loader: 'file-loader',
                options: {
                    outputPath: 'assets/dist/fonts/''
                }
            }
        ]
    })
    .configureFilenames({
        fonts: 'fonts/[name].[ext]'
    })