我正在尝试使用Webpack对Bootstrap和Font-awesome做一个简单的要求。我设法加载了 Bootstrap CSS,但 Font-awesome 无法正常工作。
这是我得到的结果:
我的代码如下。我在这里做错了什么?
资源:此处提供Github 代码。
包.json
{
"name": "",
"version": "0.0.1",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "webpack -w"
},
"license": "MIT",
"devDependencies": {
"css-loader": "^0.21.0",
"expose-loader": "^0.7.0",
"file-loader": "^0.8.4",
"style-loader": "^0.13.0",
"url-loader": "^0.5.6",
"webpack": "^1.12.2"
},
"dependencies": {
"admin-lte": "^2.3.2",
"bootstrap": "^3.3.5",
"bootstrap-webpack": "0.0.5",
"exports-loader": "^0.6.2",
"extract-text-webpack-plugin": "^0.8.2",
"font-awesome": "^4.4.0",
"font-awesome-webpack": "0.0.4",
"imports-loader": "^0.6.5",
"jquery": "^2.1.4",
"less": "^2.5.3",
"less-loader": "^2.2.1"
}
}
入口点:index.js
var $ = require('jquery');
require('expose?$!expose?jQuery!jquery');
require("bootstrap-webpack");
require('./node_modules/font-awesome/css/font-awesome.css');
require('./resources/css/style.css');
$('h1').html('<i class="fa fa-bars"></i> this is bootstrap');
console.log('hi there');
Webpack 配置文件webpack.config.js
module.exports = {
entry: './index.js',
output: {
path: 'public/assets/',
filename: 'bundle.js'
},
devtool: 'source-map',
module: {
loaders: [
{test: /\.css$/, loader: "style!css!" },
{ test: /\.less$/, loader: "style!css!less!" },
//bootstrap
{test: /\.(woff|woff2)(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=application/font-woff'},
{test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=application/octet-stream'},
{test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: 'file'},
{test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=image/svg+xml'},
//font-awesome
{ test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: "url-loader?limit=10000&minetype=application/font-woff" },
{ test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: "file-loader" }
]
},
}