javascript - 使用 Bootstrap 3 配置 webpack 4
问题描述
我只想用 Webpack 4 配置 Bootstrap。我MiniCssExtractPlugin
用来加载 css 和 sass。这是我的Webpack 配置:
const path = require('path');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const HtmlWebpackPlugin = require('html-webpack-plugin');
const WebpackMd5Hash = require('webpack-md5-hash');
module.exports = {
entry: { main: './src/index.js' },
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].[chunkhash].js'
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
},
{
test: /\.scss$/,
use: [ 'style-loader', MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader']
},
{
test: /\.(png|woff|woff2|eot|ttf|svg)$/,
loader: "url?limit=5000"
}
]
},
plugins: [
new MiniCssExtractPlugin({
filename: 'style.[contenthash].css',
}),
new HtmlWebpackPlugin({
inject: false,
hash: true,
template: './src/index.html',
filename: 'index.html'
})
]
};
我只想添加引导程序并使用它。这是我的index.js
import 'bootstrap/dist/css/bootstrap.css'
import "./assets/main.scss"
console.log("Hello")
当我想运行它时,我得到了错误:
ERROR in ./node_modules/bootstrap/dist/css/bootstrap.css 7:5
Module parse failed: Unexpected token (7:5)
You may need an appropriate loader to handle this file type.
| */
| /*! normalize.css v3.0.3 | MIT License | github.com/necolas/normalize.css */
> html {
| font-family: sans-serif;
| -webkit-text-size-adjust: 100%;
@ ./src/index.js 3:0-43
有什么帮助吗?欣赏它
解决方案
将此添加到您的配置中。
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
},
{
test: /\.scss$/,
use: [ MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader']
},
{
test: /\.css$/,
use: [ MiniCssExtractPlugin.loader, 'css-loader']
},
{
test: /\.(png|woff|woff2|eot|ttf|svg)$/,
loader: "url?limit=5000"
}
]
},
推荐阅读
- javascript - 在验证器中快速返回未定义
- c - 修复异常原因后 GDB 恢复执行
- sql - 查询性能问题(WHERE 字段 IN 数组)
- python - AttributeError:“学生”对象没有属性“calculateGrade”
- gradle - Checkstyle gradle 使用谷歌检查
- tensorflow - 如何结合 CNN 和 LSTM?
- python - Maya python api乘法节点
- php - 如何在 CakePHP 中配置会话生命周期仅持续 24 小时?
- swift - path(in:) 未按预期顺序调用
- c# - C# HTTP 错误 413.1 - 请求实体太大 - 无法正常处理此错误