vue.js - 导入css文件时出现未知字错误
问题描述
我正在尝试为我的项目导入材料图标(按照以下说明:https ://vuetifyjs.com/en/framework/icons )
nuxt.config.js
...
extend(config, {isDev, isClient, isServer}) {
if (isDev && isClient) {
config.module.rules.push({
enforce: 'pre',
test: /\.(js|vue)$/,
loader: 'eslint-loader',
exclude: /(node_modules)/
},
{
enforce: 'pre',
test: /\.css$/,
use: ['style-loader', 'css-loader']
},
{
test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/,
loader: 'url-loader',
options: {
limit: 10000
}
}
)
}
if (isServer) {
config.externals = [
nodeExternals({
whitelist: [/^vuetify/]
})
]
}
}
...
但是当我尝试运行项目时,出现了这个错误:
ERROR Failed to compile with 1 errors 4:05:21 PM
error in ./node_modules/material-design-icons-iconfont/dist/material-design-icons.css
Module build failed: Syntax Error
(2:1) Unknown word
1 |
> 2 | var content = require("!!../../css-loader/index.js!./material-design-icons.css");
| ^
3 |
4 | if(typeof content === 'string') content = [[module.id, content, '']];
@ ./node_modules/material-design-icons-iconfont/dist/material-design-icons.css 4:14-188 13:3-17:5 14:22-196
@ ./plugins/vuetify.js
@ multi vue vue-router vue-meta vuex vue-style-loader/lib/addStylesClient css-loader/lib/css-base ~/plugins/vuetify.js
我的 vuetify.js 文件
import Vuetify from 'vuetify'
import Vue from 'vue'
import 'material-design-icons-iconfont/dist/material-design-icons.css'
Vue.use(Vuetify)
我不知道我做错了什么,请帮我指出。非常感谢。
解决方案
So the way I resolve this problem is add it according to @Allkin's comment:
nuxt.config.js
css: [
'~/assets/style/app.styl',
'material-design-icons-iconfont/dist/material-design-icons.css'
],
Also I removed this in nuxt.config.js, otherwise it still have the same error
{
enforce: 'pre',
test: /\.css$/,
use: ['style-loader', 'css-loader']
},
{
test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/,
loader: 'url-loader',
options: {
limit: 10000
}
}
推荐阅读
- sql - 按 2 列的最新日期排序
- http - 允许从不同的源子域使用 cookie
- tcp - libp2p 节点给出错误:连接 ECONNREFUSED
- javascript - Best way to set dimensions for Material UI dialog on mobile?
- python - The root node feature selection in sklearn DecisionTreeClassifier
- php - Rewrite rule for dynamic slashes
- python - Flask 请求解析器拆分字符串但不拆分布尔值
- bash - 使 sxhkd 和弦以不同的顺序工作 - sxhkd 不允许更改键顺序
- reactjs - IIS 两个站点使用相同的 url,ReactJS 前端,ASP Net Core 后端,无法访问后端
- ruby - Capybara 在附加文件时返回参数错误