[英]webpack css loader doesn't work
Hello I'm trying to load bootstrap css through webpack style-loader in my vue2js SPA. 您好我正在尝试通过我的vue2js SPA中的webpack style-loader加载bootstrap css。
I installed style loader with npm install --save-dev css-loader
and I've got it in devDependiecies
of package.json
. 我用
npm install --save-dev css-loader
安装了样式加载npm install --save-dev css-loader
,我在package.json
devDependiecies
中得到了它。 I also added following to my webpack.conf.js : 我还在webpack.conf.js中添加了以下内容 :
{
test: /\.css$/,
use: [ 'style-loader', 'css-loader' ]
}
Then I installed bootstrap css throught 然后我安装了bootstrap css
npm install bootstrap@4.0.0-beta.3
And last thing I did is import bootstrap css in main.js 我做的最后一件事是在main.js中导入bootstrap css
import '../node_modules/bootstrap/dist/css/bootstrap.css'
import '../node_modules/bootstrap-vue/dist/bootstrap-vue.css'
I also tried like this: 我也尝试过这样:
import 'bootstrap/dist/css/bootstrap.css'
import 'bootstrap-vue/dist/bootstrap-vue.css'
and like this: 和这样:
import './../node_modules/bootstrap/dist/css/bootstrap.css'
import './../node_modules/bootstrap-vue/dist/bootstrap-vue.css'
This doesn't work giving me this error in command line(AFTER SERVER START): 这不能在命令行中给出这个错误(AFTER SERVER START):
ERROR in ./src/main.js Module not found: Error: Can't resolve '../node_modules/bootstrap-vue/dist/bootstrap-vue.css' in 'C:\\Users\\Adm\\Documents\\TheStockerTrader\\src' @ ./src/main.js 7:0-62 @ multi main
./src/main.js中的错误找不到模块:错误:无法解析'C:\\ Users \\ Adm \\ Documents \\ TheStockerTrader \\中的'../node_modules/bootstrap-vue/dist/bootstrap-vue.css' src'@ ./src/main.js 7:0-62 @ multi main
ERROR in ./src/main.js Module not found: Error: Can't resolve 'style-loader' in 'C:\\Users\\Adm\\Documents\\TheStockerTrader' @ ./src/main.js 6:0-58 @ multi main
./src/main.js中的错误找不到模块:错误:无法解析'C:\\ Users \\ Adm \\ Documents \\ TheStockerTrader'中的'style-loader'@。/ src / main.js 6:0-58 @多主
And this errors in chrome console: 而Chrome控制台中的这个错误:
resolve 'bootstrap-vue/dist/bootstrap-vue.css' in 'C:\\Users\\Adm\\Documents\\TheStockerTrader\\src' Parsed request is a module using description file: C:\\Users\\Adm\\Documents\\TheStockerTrader\\package.json (relative path: ./src) Field 'browser' doesn't contain a valid alias configuration
解析'C:\\ Users \\ Adm \\ Documents \\ TheStockerTrader \\ src'中的'bootstrap-vue / dist / bootstrap-vue.css'解析请求是一个使用描述文件的模块:C:\\ Users \\ Adm \\ Documents \\ TheStockerTrader \\ package .json(相对路径:./ src)字段“浏览器”不包含有效的别名配置
Module not found: Error: Can't resolve '../node_modules/bootstrap-vue/dist/bootstrap-vue.css' in 'C:\\Users\\Adm\\Documents\\TheStockerTrader\\src'
找不到模块:错误:无法解析'C:\\ Users \\ Adm \\ Documents \\ TheStockerTrader \\ src'中的'../node_modules/bootstrap-vue/dist/bootstrap-vue.css'
What I'm doing wrong, why my css-loader doesn't work? 我做错了什么,为什么我的css-loader不起作用? It says that it can't find bs module but I'm sure I installed it, I also checked if it is present in my node_modules folder and it is:
它说它找不到bs模块,但我确定我安装了它,我还检查了它是否存在于我的node_modules文件夹中,它是:
Did you install style loader as well: 你也安装了样式加载器:
npm install style-loader --save-dev
Then set as a loader: 然后设置为加载器:
{
module: {
rules: [
{
test: /\.css$/,
use: [
{ loader: "style-loader" },
{ loader: "css-loader" }
]
}
]
}
}
Try this 试试这个
module : {
rules : [
...
{
test: /\.css$/,
include: helpers.root('src', 'app'),
loader: 'raw-loader'
},
// // css global which not include in components
{
test: /\.css$/,
exclude: path.join(__dirname, '/src/app'),
use: ExtractTextPlugin.extract({
use: 'raw-loader'
})
},
]...
}
plugin : [
...
new ExtractTextPlugin(
'[name].css'
),
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.