有人知道这个是为什么吗?

来源:2-1 vue-loader+webpack项目配置

qq_lcsteamon_0

2018-11-10 12:17

ERROR in ./src/app.vue

Module build failed (from ./node_modules/vue-loader/index.js):

TypeError: Cannot read property 'vue' of undefined

    at Object.module.exports (D:\vuePro\vue-ssr-tech\node_modules\vue-loader\lib\loader.js:61:18)

 @ ./src/index.js 2:0-27 8:21-24


写回答 关注

2回答

  • qq_lcsteamon_0
    2018-11-14 10:58:32

    3q,还是插件的版本有问题。

  • qq__eGJOWX
    2018-11-12 17:30:53

    关键的代码:webpack.config.js中

    const path=require('path')
    
    const isDev=process.env.NODE_ENV ==='development'
    const HTMLPlugin=require('html-webpack-plugin')
    const webpack=require('webpack')
    
    const config = {
        target:'web',
        entry: path.join(__dirname,'src/index.js'),
        output:{
            filename:'bundle.js',
            path:path.join(__dirname,'dist')
        },
        module:{
            rules:[
                {
                    test:/\.vue$/,
                    loader:'vue-loader'
                },
                {
                    test: /\.css$/,
                    use: [
                        'style-loader',
                        'css-loader'
                    ]
                },
                {
                    test:/\.styl/,
                    use:[
                        'style-loader',
                        'css-loader',
                        'stylus-loader'
                    ]
                },
                {
                    test: /\.(gif|jpg|jpeg|png|svg)$/,
                    use: [
                        {
                            loader:'url-loader',
                            options:{
                                limit:1024,
                                name:'[name]-a.[ext]'
                            }
                        }
                    ]
                }
            ]
        },
        plugins: [
            new webpack.DefinePlugin({
                'process.env':{
                    NODE_ENV:isDev?'"development"':'"production"'
                }
            }),
            
            new HTMLPlugin()
        ]
    }
    
    if(isDev){
        config.devtool="#cheap-module-eval-source-map"
        config.devServer={
            port:8000,
            host:'0.0.0.0',
            overlay:{
                errors:true
            },
            open:true,
            hot:true
        }
        config.plugins.push(
            new webpack.HotModuleReplacementPlugin(),
            new webpack.NoEmitOnErrorsPlugin()
        )
    }
    
    module.exports=config


    qq__eG...

    粘贴进去给我删了这关键的地方了,什么鬼 const VueLoaderPlugin = require('vue-loader/lib/plugin'); new VueLoaderPlugin(),

    2018-11-12 17:33:56

    共 3 条回复 >

Vue+Webpack打造todo应用

用前端最热门框架Vue+最火打包工具Webpack打造todo应用

84606 学习 · 787 问题

查看课程

相似问题