使用React 16,Bootstrap 3,Webpack 2和Typescript 2.3。如何限制Webpack/Bootstrap使用的字体格式?
默认情况下,引导包括WOFF
,WOFF2
,EOT
,TTF
和SVG
字体格式为Glyphicons-Halflings
FONT-FAMILY。
我很高兴只支持WOFF
字体格式 - 或者至少,我绝对不希望处理EOT
因为我不支持IE8,和SVG
和TTF
是烦人大。
嵌入字体到我的javascript交付通过此配置的WebPack做:
module: {
rules: [
{test: /\.(tsx|ts)$/, loader: "awesome-typescript-loader"},
{test: /\.css$/, use: ['style-loader', 'css-loader']},
{test: /\.(png|woff|woff2|eot|ttf|svg)$/,
loader: 'url-loader?limit=10240',
options: { name: '[path][name].[ext]'},
},
{test: /\.js$/, enforce: "pre", loader: "source-map-loader"},
]
},
实际上,我不知道怎么说网址装载机配置工程。我最初只是试图让字体文件被处理,而不会用内容哈希来改变他们的名字。但是相反,Webpack将它们嵌入到JavaScript文件中,我决定更喜欢它 - 特别是如果我可以通过剥离其他字体格式来缩小尺寸。
起初,我想我可能只是省略了字体格式从网址加载器的配置,如:
{test: /\.(png|woff)$/,
loader: 'url-loader?limit=10240',
options: { name: '[path][name].[ext]'},
},
但失败与这些样的错误:
ERROR in ./~/bootstrap/dist/fonts/glyphicons-halflings-regular.eot
Module parse failed: ....\node_modules\bootstrap\dist\fonts\glyphicons-halflings-regular.eot Unexpected character '�' (1:0)
You may need an appropriate loader to handle this file type.
(Source code omitted for this binary file)
@ ./~/css-loader!./~/bootstrap/dist/css/bootstrap.css 6:4445-4497 6:4520-4572
@ ./~/bootstrap/dist/css/bootstrap.css
@ ./src/main/ts/AppReactRoot.tsx
所以我想也许我可以覆盖我的app.css
文件中的引导字体,并且只指定单个字体格式,例如:
@font-face {
font-family: "Glyphicons Halflings";
src: url("~bootstrap/dist/css/bootstrap.css") format('woff');
font-weight: normal;
}
但这似乎没有什么区别。该app.css
文件,如果它的确与众不同,看起来是这样的:
import * as React from "react";
import * as ReactDOM from "react-dom";
import "bootstrap/dist/css/bootstrap.css";
import './app.css';
import {UserApp} from "app/UserApp";
ReactDOM.render(
<UserApp/>,
document.getElementById("root")
);
所以,问题是:我怎样才能让我只使用了WOFF
字体格式重写引导默认值?