Laravel 5.4 - Bootstrap 字形在 sass 集成后不起作用

Laravel 5.4 - Bootstrap glyphicons don't work after sass integration

好吧,我刚刚安装了新的 Laravel 5.4。然后安装了 npm 并决定第一次使用 webpack 而不是 gulp.js。如您所知,Laravel 默认提供 sass Bootstrap 集成。使用此命令从 sass.

生成我的 css

npm run dev

Bootstrap、Jquery 运行完美,但未显示 Glyphicons。检查我的 public/css/app.css 我发现 Glyphicons 字体路径不合适。

 src: url(/fonts/glyphicons-halflings-regular.eot?f4769f9bdb7466be65088239c12046d1);

如果我手动使用 ../fonts 而不是 /fonts 它将起作用。我试图找出并编辑默认路径。在 _variables.css 我设置:

$icon-font-path = "../fonts" - but npm gives error.

默认为:"~bootstrap-sass/assets/fonts/bootstrap/"

复制字体文件夹到 puclic/css 文件夹,没有用。

webpack.mix.js 文件添加了选项:

options({processCssUrls: false})

并在 _variables.css 中再次设置:

$icon-font-path = "../fonts"

运行 npm-run-dev 它起作用了,显示了字形。但是,我不想为 processCssUrls 设置 false。因为,在这种情况下,我将无法使用命令最小化 css 个文件:npm run production.

此外,我关注了这个问题,但找不到任何答案,所有解决方案均无效。

glyphicons not showing with sass bootstrap integration

终于找到解决办法了。在 webpack.config.js 中设置:

publicPath: '../'

而不是Mix.resourceRoot

{
    test: /\.(woff2?|ttf|eot|svg|otf)$/,
    loader: 'file-loader',
    options: {
        name: 'fonts/[name].[ext]?[hash]',
        publicPath: Mix.resourceRoot
    }
},