[英]Scoped css not copied in vue component
I have a scoped style tag in my vue component:我的 vue 组件中有一个作用域样式标签:
<style scoped>
.ttt{
background-color: red;
}
</style>
When I build my project with npm and webpack, the styles are not copied.当我使用 npm 和 webpack 构建项目时,不会复制 styles。 I already configured css to have it parsed by
postCss
to solve it:我已经配置了 css 让它被
postCss
解析来解决它:
var path = require('path');
const VueLoaderPlugin = require('vue-loader/lib/plugin');
module.exports = {
mode: 'development',
devtool: 'source-map',
entry: {
build: './assets/js/main.js'
},
output: {
path: path.resolve(__dirname, './dist'),
publicPath: './dist/',
filename: '[name].js'
},
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader'
},
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: ['@babel/preset-env']
}
}
},
{//required for css in vue components
test: /\.css$/,
use: [
'vue-style-loader',
{
loader: 'css-loader',
options: { importLoaders: 1 }
},
'postcss-loader'
]
},
{
test: /\.svg$/,
oneOf: [
{
resourceQuery: /inline/,
use: [
'babel-loader',
{
loader: 'vue-svg-loader',
options: {
svgo: {
plugins: [
{ cleanupIDs: false },
{ collapseGroups: false },
],
},
}
},
],
},
{
type: 'asset/resource',
generator: {
filename: '[name].[ext]?[hash]'
}
},
],
},
]
},
resolve: { alias: { vue: 'vue/dist/vue.esm.js' } },
plugins: [
new VueLoaderPlugin()
],
performance: {
hints: 'warning'
}
};
There is no error outputted in npm or the browser console. npm或浏览器控制台没有输出错误。
Am I missing something?我错过了什么吗?
Versions:版本:
"dependencies": {
"axios": "^0.18.0",
"vue": "^2.6.12",
"vue-excel-editor": "1.3.90",
},
"browserslist": [
"> 1%",
"last 2 versions",
"not ie <= 8"
],
"devDependencies": {
"@babel/core": "^7.12.10",
"babel-loader": "^8.2.2",
"@babel/preset-env": "^7.12.11",
"cross-env": "^5.0.5",
"css-loader": "^5.0.1",
"postcss": "^8.2.2",
"postcss-loader": "^4.1.0",
"terser-webpack-plugin": "^5.0.3",
"vue-loader": "^15.9.6",
"vue-style-loader": "^4.1.2",
"vue-svg-loader": "^0.16.0",
"vue-template-compiler": "^2.6.12",
"webpack": "^5.11.1",
"webpack-cli": "^4.1.1",
"webpack-merge": "^5.7.3"
}
Try change options: { importLoaders: 1 }
to options: { importLoaders: 2 }
.尝试将
options: { importLoaders: 1 }
更改为options: { importLoaders: 2 }
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.