首页 > webpack+babel+vue在webpack编译的时候报错

webpack+babel+vue在webpack编译的时候报错

出错信息为

ERROR in ./js_src/torrents_list.vue
Module parse failed: /home/gao/workspace/transmission-web/js_src/torrents_list.vue Unexpected token (1:0)
You may need an appropriate loader to handle this file type.

以下是webpack.config.js

webpack = require('webpack')   
vue = require('vue-loader')

module.exports = {
  entry: './js_src/main.js',
  output: {
    path: 'public/scripts/',   
    filename: 'bundle.js'
  },
  resolve: {
    extensions: ['', '.js', '.vue'],
    modulesDirectories: ['node_modules']
  },
  module: {
    loaders: [
      {loader: 'vue', test: '/\.vue$/'}, 
      {loader: 'babel', exclude: 'node_modules', test: /\.js$/}
    ]
  },
  babel: {
    presets: ['es2015'],
    plugins: ['transform-runtime']
  },
  plugins: [new webpack.ProvidePlugin({$: "jquery", jQuery: "jquery"})]

以下是js_src/main.js

import Vue from 'vue';         
var jquery = require('jquery');
var bootstrap = require('bootstrap');
import TorrentsList from './torrents_list.vue';

var torrentList = new Vue({    
  el: "#torrents_list",
  components: {
    torrents_list: TorrentsList
  },
  data: {                      
    torrents: []               
  }
})
  
$.get('/j_get_torrents', success= (e) => {
  torrentList.torrents = e.arguments.torrents;
  }
)

js_src/torrents_list.vue

<template lang="jade">
   ul(v-for="torrent in torrents")
     li
       .torrent-name
         {{torrent.name}}
       .torrent-size
         {{torrent.totalSize}}
</template>

<script>
  module.exports = {
    data: function() {
      return {
        torrents: []
      };
    }
  }
</script>

写完发现把一些调试用的东西弄上去了,大家凑合看吧,我平时写代码没这么难看……


找到问题了……test那里的regexp不应该加引号……

【热门文章】
【热门文章】