javascript - webpack vue-loader 无效
ringa_lee
ringa_lee 2017-04-11 09:03:22
[JavaScript讨论组]

webpack 编译成功 打开index.html出现错误:

编译成功提示:

webpack.config.js

var path = require('path');

module.exports = {
    entry: path.resolve(__dirname, '../app/index/index.js'),
    output: {
        path: path.resolve(__dirname, '../public/static'),
        publicPath: 'static/',
        filename: '[name].[hash].js',
        chunkFilename: '[id].[chunkhash].js'
    },
    resolve: {
        extensions: ['', '.js', '.vue'],
    },
    module: {
        loaders: [
            {
                test: /\.vue$/, 
                loader: 'vue' ,
                exclude: /node_modules/
                  
            },
            {
                test: /\.js$/,
                loader: 'babel?presets=es2015',
                exclude: /node_modules/
            }
        ]
    }
}

index.js

import Vue from 'Vue'
import Favlist from './components/Favlist'

new Vue({
    el: '#app', 
    components: { Favlist }
})

Favlist.vue

<template>
    <p>{{ msg }}</p>
</template>

<script>
    export default {
        data () {
            return {
                msg: 'Hello World!!!'
            }
        }
    }
</script>

<style>
    html{
        background: red;
    }
</style>
ringa_lee
ringa_lee

ringa_lee

全部回复(4)
迷茫

应该是es2015的presets没有生效,建议babel的配置放在项目根目录的.babelrc中。可以看看这篇文章

巴扎黑

使用 vue-cli:

$ vue list
$ vue init webpack my_project
PHP中文网

export default 不支持放在函数内

PHP中文网

这么写试试看

module: {
preLoaders:[
{
            test: /\.js$/,
            loader: 'babel?presets=es2015',
            exclude: /node_modules/
        }
       
    ],
    loaders: [
         {
            test: /\.vue$/, 
            loader: 'vue' ,
            exclude: /node_modules/
              
        }
    ]
}
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号