问答详情
源自:2-1 vue-loader+webpack项目配置

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

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


提问者:qq_lcsteamon_0 2018-11-10 12:17

个回答

  • 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