vue.js - vue:你可能需要一个合适的加载器来处理这个文件类型
问题描述
我将我的项目从 webpack3.x 升级到 webpack4.28.4,当我运行 webpack 进行生产时,它向我显示错误!
ERROR in ./src/router/_import_production.js 9:11
Module parse failed: Unexpected token (9:11)
You may need an appropriate loader to handle this file type.
| module.exports = function (file) {
| return function () {
> return import("@/views/" + file + ".vue");
| };
| };
@ ./src/router/index.js 8:14-58
@ ./src/main.js
我用happypack来提高编译速度!
const HappyPack = require('happypack')
const os = require('os')
const happyThreadPool = HappyPack.ThreadPool({
size: os.cpus().length
})
{
test: /\.vue$/,
loader: 'vue-loader',
options: vueLoaderConfig
},
{
test: /\.js$/,
use: 'happypack/loader?id=babel',
include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')]
}
new HappyPack({
id: 'babel',
loaders: [{
loader: 'babel-loader',
query: {
cacheDirectory: true
}
}],
threadPool: happyThreadPool,
verbose: true
})
它没有用!任何人都可以解决我的问题吗?非常感谢!
解决方案
_import_production.js 修改这个文件
module.exports = file => require('@/views/' + file + '.vue').default
推荐阅读
- python - 在 SQLAlchemy 的原始 SQL 查询中实现占位符
- installshield - 如何修复 InstallShield 向导错误 -5011:0x8000ffff?
- stack - 如何检查 Maxima 中的输入字段是否为空?
- kubernetes - kubeadm init:clusterDND IP 的推荐值
- pointers - 为什么 Go 标准库更喜欢指针接收器?
- windows - 获取当前路径的一部分
- powershell - 有没有办法使用 Powershell 在浏览器中打开具有指定 cookie 的网站?
- wpf - 如何确定 WPF 中 RelativeSource 的 AncestorLevel?
- wordpress - 无限循环 Wordpress 301 重定向 AWS CloudFront 负载均衡器和 LightSail
- android - 无法在线性布局中插入按钮