gpt4 book ai didi

twitter-bootstrap - 带 bo​​otstrap.css 的 webpack 不起作用

转载 作者:行者123 更新时间:2023-11-28 04:20:23 25 4
gpt4 key购买 nike

这是我的webpack.config.js文件:

var ExtractTextPlugin = require('extract-text-webpack-plugin'),
webpack = require('webpack');

module.exports = {
entry: [
'./src/app.js',
],
output: {
path: __dirname + '/../web/js',
filename: 'build.js',
},
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader'
},
{
test: /\.css$/,
loader: ExtractTextPlugin.extract('style-loader', 'css-loader')
},
{
test: /\.(png|woff|woff2|eot|ttf|svg)$/,
loader: "url?limit=5000"
}
]
},
plugins: [
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery"
}),
new ExtractTextPlugin('build.css')
]
}

这是我的package.json文件:

"dependencies": {
"angular": "^1.6.4",
"babel-core": "^6.25.0",
"babel-loader": "^7.1.1",
"babel-polyfill": "^6.23.0",
"babel-preset-es2015": "^6.24.1",
"bootstrap": "^3.3.7",
"css-loader": "^0.28.4",
"extract-text-webpack-plugin": "^3.0.0",
"file-loader": "^0.11.2",
"jquery": "^3.2.1",
"style-loader": "^0.18.2",
"url-loader": "^0.5.9",
"webpack": "^3.4.1"
}

这是我的 app.js 文件:

import 'babel-polyfill';
import $ from 'jquery';
import 'bootstrap/dist/js/bootstrap.js';
import 'bootstrap/dist/css/bootstrap.css';

尝试启动 webpack 后出现错误。

ERROR in ./node_modules/bootstrap/dist/css/bootstrap.css Module parse failed:
/var/www/dcracks/app/webpack/node_modules/bootstrap/dist/css/bootstrap.css
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%;
@ ./node_modules/bootstrap/dist/css/bootstrap.css 4:14-42
@ ./src/app.js @ multi ./src/app.js

我已经重读了一堆 Material ,并在各个论坛上删除了一堆帖子。我做错了什么?

最佳答案

signature of ExtractTextPlugin.extract是:

ExtractTextPlugin.extract(options: loader | object)

由于没有第二个参数,因此您的 css-loader 未被使用。最常见的配置是使用 css-loader 来处理 CSS 文件,并使用 style-loader 作为后备,当不应该提取时使用(配置的加载器仍会应用,但不会被提取,而是使用后备加载器)。

您可以使用 Readme - Usage 中显示的规则.

{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: 'css-loader'
})
}

关于twitter-bootstrap - 带 bo​​otstrap.css 的 webpack 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45499348/

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