我正在使用React、Bootstrap和Webpack构建应用程序,使用Babel处理ES6语法。
但是我无法将boostrap.js和bootstrap.css导入到我的应用程序中。
我的webpack.config.js文件如下:
var webpack = require('webpack'),
HtmlWebpackPlugin = require('html-webpack-plugin'),
path = require('path'),
srcPath = path.join(__dirname, 'src');
module.exports = {
target: 'web',
cache: true,
entry: {
module: path.join(srcPath, 'module.js'),
common: ['react', 'react-router', 'alt']
},
resolve: {
root: srcPath,
extensions: ['', '.js'],
modulesDirectories: ['node_modules', 'src']
},
output: {
path: path.join(__dirname, 'tmp'),
publicPath: '',
filename: '[name].js',
library: ['Example', '[name]'],
pathInfo: true
},
module: {
loaders: [
{test: /\.js?$/, exclude: /node_modules/, loader: 'babel?cacheDirectory'}
]
},
plugins: [
new webpack.optimize.CommonsChunkPlugin('common', 'common.js'),
new HtmlWebpackPlugin({
inject: true,
template: 'src/index.html'
}),
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery"
}),
new webpack.ProvidePlugin({
bootstrap: "bootstrap.css",
}),
new webpack.NoErrorsPlugin()
],
debug: true,
devtool: 'eval-cheap-module-source-map',
devServer: {
contentBase: './tmp',
historyApiFallback: true
}
};
在我的.js文件(React组件)中,我想做:import 'bootstrap'。但是CSS没有被实现。.js导入运作良好。
那么,我该如何导入Bootstrap或配置webpack?