gpt4 book ai didi

javascript - 使用 Bootstrap 3 配置 webpack 4

转载 作者:行者123 更新时间:2023-11-30 20:03:58 24 4
gpt4 key购买 nike

我只想使用 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'
})

]
};

我只想添加 Bootstrap 并使用它。这是我的 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 - 使用 Bootstrap 3 配置 webpack 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53103312/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com