Pak*_*wat 7 webpack vue.js css-loader vue-loader
我使用Webpack创建了我的项目并在开发中使用了Vue.js,但我无法注入<style>Vue模板.
它让我
Module parse failed: Unexpected token (18:5)
You may need an appropriate loader to handle this file type.
|
|
> body {
| background-color: red;
| }
Run Code Online (Sandbox Code Playgroud)
这是我的 webpack.config.js
...
module: {
rules: [{
test: /\.vue$/,
loader: "vue-loader"
},
{
test: /\.js$/,
loader: "babel-loader",
exclude: /node_modules/,
options: {
presets: ["@babel/preset-env"]
}
},
]
},
Run Code Online (Sandbox Code Playgroud)
还有我的 App.vue
<template>
<div id="app">
<counter></counter>
</div>
</template>
<script>
import Counter from "./app/Counter.vue";
export default {
name: "app",
components: {
counter: Counter
}
};
</script>
<style>
body {
background-color: red;
}
</style>
Run Code Online (Sandbox Code Playgroud)
小智 18
有同样的问题.查看vue-loader css 的文档也需要规则.
安装包vue-style-loader和css-loader
将以下内容添加到您的rules部分webpack.config.js:
{
test: /\.css$/,
use: [
'vue-style-loader',
'css-loader'
]
},
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6312 次 |
| 最近记录: |