Cha*_*ith 3 ecmascript-6 webpack vue.js
导入不带.vue扩展名的vue文件时出现以下错误。
./~/babel-loader/lib!./~/vue-loader/lib/selector.js?type=script&index=0!./src/App.vue中找不到错误:错误:无法解析' ./components/Navbar'
我的Web back配置如下
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
// Since sass-loader (weirdly) has SCSS as its default parse mode, we map
// the "scss" and "sass" values for the lang attribute to the right configs here.
// other preprocessors should work out of the box, no loader config like this necessary.
'scss': 'vue-style-loader!css-loader!sass-loader',
'sass': 'vue-style-loader!css-loader!sass-loader?indentedSyntax'
}
// other vue-loader options go here
}
},
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.(png|jpg|gif|svg)$/,
loader: 'file-loader',
options: {
name: '[name].[ext]?[hash]'
}
}
]
},
resolve: {
alias: {
'vue$': 'vue/dist/vue.esm.js'
}
},
Run Code Online (Sandbox Code Playgroud)
问题出在您的Webpack配置中。要使Webpack自动解析.vue扩展名,请使用resolve.extensions选项,并包括默认值。
resolve: {
extensions: ['*', '.js', '.vue', '.json']
}
Run Code Online (Sandbox Code Playgroud)
问题出在 Webpack 配置上。
.vue通过在 Webpack 中包含扩展数组,使 Webpack 自动解析扩展resolve
resolve: {
extensions: ['.vue'],
},
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1799 次 |
| 最近记录: |