当前位置: 首页 > 知识库问答 >
问题:

vue:您可能需要适当的加载程序来处理此文件类型

羊刚捷
2023-03-14

我从webpack3升级了我的项目。x到网页4。28.4,当我运行用于生产的网页包时,它向我显示错误!


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
})

它没有工作!有人能解决我的问题吗?非常感谢!

共有1个答案

游安康
2023-03-14

_import_production.js修改这个文件

module.exports = file => require('@/views/' + file + '.vue').default
 类似资料: