Webpack vue-loader gives an "unexpected token" for a single-page .vue component

I am primarily a C # developer and am trying to learn Vue.js. I am using Visual Studio 2017 + ASP.NET MVC (as API + single layout) + Vue.js + Webpack.
 .vuesingle-page component files are downloaded vue-loader, and .jsfiles are downloaded babel-loaderusing es2015preset.

app.jssuccessfully transferred to a file dist/script.jsin a Babel file, but the .vuefiles give me syntax errors, no matter what combinations I use. I have the same error, even if my error is navigation.vue completely empty :

A mistake in. /assets/component/navigation.vue
Module build error: SyntaxError: Unexpected token {

Contents of Task Manager Launch Explorer:

enter image description here

nagivation.vue

<template>
    <div>
        {{ greeting }}
    </div>
</template>

<script>
    export default {
        data: {
            greeting: 'Hello World'
        }
    }
</script>

app.js

import Vue from "../vendor/vue.js";

Vue.component("navigation", require("../component/navigation.vue"));

const app = new Vue({
    el: "#app"
}); 

webpack.config.js

module.exports = {
    entry: "./assets/core/app.js",
    output: {
        filename: "./dist/script.js"
    },
    module: {
        loaders: [
            {
                test: /\.js$/,
                loader: "babel-loader",
                exclude: /node_modules/,
                options: {
                    presets: ["es2015"]
                }
            },
            {
                test: /\.vue$/,
                loader: "vue-loader"
            }
        ]
    },
    resolve: {
      extensions: ["*", ".js", ".vue"]  
    },
    plugins: [
        new NotifierPlugin()
    ]
};

package.json

{
  "version": "1.0.0",
  "name": "helloworld",
  "private": true,
  "devDependencies": {
    "babel-cli": "^6.26.0",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-vue": "^1.2.1",
    "clean-webpack-plugin": "^0.1.17",
    "webpack": "^3.8.1"
  },
  "dependencies": {
    "babel-core": "^6.26.0",
    "babel-eslint": "^8.0.2",
    "babel-loader": "^7.1.2",
    "babel-preset-env": "^1.6.1",
    "css-loader": "^0.28.7",
    "eslint": "^4.10.0",
    "eslint-cli": "^1.1.1",
    "eslint-loader": "^1.9.0",
    "eslint-plugin-react": "^7.4.0",
    "vue-loader": "^13.5.0",
    "vue-router": "^3.0.1",
    "vue-template-compiler": "^2.5.3",
    "webpack-notifier": "^1.5.0"
  }
}

? ?

+4
1

, .vue, vue-loader. vue-loader >= 13.1 (, , vue-loader 12), , node 6.2 , vue-loader , . node, :

node --version

node, vue-loader, :

npm install vue-loader@13.0.1 --save-dev

, , .

babel-preset-env, babel-preset-2015, ( ) .

+3

Source: https://habr.com/ru/post/1689058/


All Articles